scratch_space 0.0.3+2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 70

Build Status

ScratchSpace

A ScratchSpace is a thin wrapper around a temporary directory. The constructor takes zero arguments, so making one is as simple as doing new ScratchSpace().

In general, you should wrap a ScratchSpace in a Resource, so that you can re-use the scratch space across build steps in an individual build. This is safe to do since you are not allowed to overwrite files within a build.

This should look something like the following:

final myScratchSpaceResource =
    new Resource(() => new ScratchSpace(), dispose: (old) => old.delete());

And then you can get access to it through the BuildStep#fetchResource api:

class MyBuilder extends Builder {
  Future build(BuildStep buildStep) async {
    var scratchSpace = await buildStep.fetchResource(myScratchSpaceResource);
  }
}

Adding assets to a ScratchSpace

To add assets to the ScratchSpace, you use the ensureAssets method, which takes an Iterable<AssetId> and an AssetReader (for which you should generally pass your BuildStep which implements that interface).

You must always call this method with all assets that your external executable might need in order to set up the proper dependencies and ensure hermetic builds.

Note: It is important to note that the ScratchSpace does not guarantee that the version of a file within it is the most updated version, only that some version of it exists. For this reason you should create a new ScratchSpace for each build using the Resource class as recommended above.

Deleting a ScratchSpace

When you are done with a ScratchSpace you should call delete on it to make sure it gets cleaned up, otherwise you can end up filling up the users tmp directory.

Note: You cannot delete individual assets from a ScratchSpace today, you can only delete the entire thing. If you have a use case for deleting individual files you can file an issue.

Getting the actual File objects for a ScratchSpace

When invoking an external binary, you probably need to tell it where to look for files. There are a few fields/methods to help you do this:

  • String get packagesDir: The packages directory in the ScratchSpace.
  • String get tmpDir: The root temp directory for the ScratchSpace.
  • File fileFor(AssetId id): The File object for id.

Copying back outputs from the temp directory

After running your executable, you most likely have some outputs that you need to notify the build system about. To do this you can use the copyOutput method, which takes an AssetId and AssetWriter (for which you should generally pass your BuildStep which implements that interface).

This will copy the asset referenced by the AssetId from the temp directory back to your actual output directory.

Feature requests and bugs

Please file feature requests and bugs at the issue tracker.

0.0.3+2

  • Declare support for package:build version 1.x.x.

0.0.3+1

  • Increased the upper bound for the sdk to <3.0.0.

0.0.3

  • Use digests to improve ensureAssets performance.
    • Scratch spaces can now be used across builds without cleaning them up, and will check digests and update assets as needed.

0.0.2+1

  • Fix a bug where failing to read an asset in serve mode could get the build stuck.

0.0.2

  • Allow creating files at the root of the scratch space.

0.0.1+3

  • Allow package:build 0.12.0

0.0.1+2

  • Allow package:build 0.11.0

0.0.1+1

  • Fix a deadlock issue around the file descriptor pool, only take control of a resource right before actually touching disk instead of also encapsulating the readAsBytes call from the wrapped AssetReader.

0.0.1

  • Initial release, adds the ScratchSpace class.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  scratch_space: ^0.0.3+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:scratch_space/scratch_space.dart';
  
Version Uploaded Documentation Archive
0.0.3+2 Sep 25, 2018 Go to the documentation of scratch_space 0.0.3+2 Download scratch_space 0.0.3+2 archive
0.0.3+1 Jul 16, 2018 Go to the documentation of scratch_space 0.0.3+1 Download scratch_space 0.0.3+1 archive
0.0.3 Jun 22, 2018 Go to the documentation of scratch_space 0.0.3 Download scratch_space 0.0.3 archive
0.0.2+1 Apr 21, 2018 Go to the documentation of scratch_space 0.0.2+1 Download scratch_space 0.0.2+1 archive
0.0.2 Mar 19, 2018 Go to the documentation of scratch_space 0.0.2 Download scratch_space 0.0.2 archive
0.0.1+3 Jan 18, 2018 Go to the documentation of scratch_space 0.0.1+3 Download scratch_space 0.0.1+3 archive
0.0.1+2 Nov 2, 2017 Go to the documentation of scratch_space 0.0.1+2 Download scratch_space 0.0.1+2 archive
0.0.1+1 Oct 4, 2017 Go to the documentation of scratch_space 0.0.1+1 Download scratch_space 0.0.1+1 archive
0.0.1 Sep 21, 2017 Go to the documentation of scratch_space 0.0.1 Download scratch_space 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, other

Primary library: package:scratch_space/scratch_space.dart with components: io, isolate, build.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use scratch_space.dart.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
build >=0.10.0 <2.0.0 1.0.1
crypto >=2.0.3 <3.0.0 2.0.6
path ^1.1.0 1.6.2
pedantic ^1.0.0 1.2.0
pool ^1.0.0 1.3.6
Transitive dependencies
analyzer 0.33.0
args 1.5.0
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.0.2
csslib 0.14.6
front_end 0.1.6
glob 1.1.7
html 0.13.3+3
kernel 0.3.6
logging 0.11.3+2
meta 1.1.6
package_config 1.0.5
plugin 0.2.0+3
source_span 1.4.1
stack_trace 1.9.3
string_scanner 1.0.4
typed_data 1.1.6
utf 0.9.0+5
watcher 0.9.7+10
yaml 2.1.15
Dev dependencies
build_runner ^0.9.0
build_test ^0.10.0
build_vm_compilers ^0.1.0
test ^1.0.0