Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/bundle-fairy

Package Overview
Dependencies
Maintainers
108
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/bundle-fairy - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

CHANGELOG.md

8

bin/bundle-fairy.js

@@ -12,2 +12,3 @@ #!/usr/bin/env node

console.error(' -o, --outfile: specify an output file path');
console.error(' -d, --dirname: (only for extract) output just the directory name instead of a list of bundled files');
console.error(' -v, --verbose: verbose error messages');

@@ -37,6 +38,9 @@ console.error(' -h, --help: show this message');

var options = {};
options.dirname = args.d || args.dirname || false;
//result:
//* true|false if command is 'isbundle'
//* [] of extracted file names/layers
fairy[cmd](zipfile, function(err, result) {
fairy[cmd](zipfile, options, function(err, result) {
if (err) return fail(err);

@@ -49,2 +53,2 @@ console.log(result);

process.exit(err.code === 'EINVALID' ? 3 : 1);
}
}

@@ -10,3 +10,3 @@ var fs = require('fs');

function isbundle(zipfile, callback) {
function isbundle(zipfile, options, callback) {

@@ -38,2 +38,4 @@ /*

if (typeof options === 'function') callback = options;
var allowed_files = ['.geojson', '.csv', '.index', '.json', '.kml', '.gpx'];

@@ -156,3 +158,6 @@

function extract(zipfile, callback) {
function extract(zipfile, options, callback) {
if (typeof options === 'function') callback = options;
isbundle(zipfile, function(err) {

@@ -164,2 +169,3 @@ if (err) return callback(err);

var layer_files = [];
zf.names.forEach(function(zip_entry) {

@@ -176,3 +182,5 @@ var out_file = path.join(extract_dir, zip_entry);

});
callback(null, layer_files.join(','));
if (options && options.dirname) return callback(null, extract_dir);
return callback(null, layer_files.join(','));
});

@@ -179,0 +187,0 @@ }

{
"name": "@mapbox/bundle-fairy",
"version": "0.0.4",
"version": "0.1.0",
"description": "Check if ZIP is a bundle and extract",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -61,7 +61,14 @@ # bundle-fairy

```javascript
// ***** exact output of this function is yet to be determined *****
fairy.extract('./path/to/file.zip', function(err, result) {
if (err) throw err;
console.log(result); // comma separated list of files within the bundle
});
```
fairy.isBundle('./path/to/file.zip', function(err, uri) {
You can pass in the `dirname` option to just get the full directory path back:
```javascript
fairy.extract('./path/to/file.zip', { dirname: true }, function(err, result) {
if (err) throw err;
console.log(uri); // uri string to extracted directory
console.log(result); // /User/waka/files/tmp-bundle
});

@@ -73,3 +80,3 @@ ```

**Check if is bundle**
```
```shell
$ bundle-fairy isbundle <zipfile>

@@ -79,4 +86,5 @@ ```

**Extract bundle**
```
```shell
$ bundle-fairy extract <zipfile>
$ bundle-fairy extract <zipfile> --dirname # returns just directory name
```

@@ -86,3 +94,3 @@

```bash
```shell
npm test

@@ -89,0 +97,0 @@ ```

@@ -7,3 +7,15 @@ var test = require('tape');

var rimraf = require('rimraf');
var exec = require('child_process').exec;
function cleanup(layers, assert) {
var parts = layers[0].split('/');
var tmp = parts[parts.indexOf('fixtures') + 1];
var tmpdir = layers[0].split(tmp)[0] + tmp;
rimraf(tmpdir, function(err) {
if (err) throw err;
assert.end();
});
}
test('valid bundles', function(t) {

@@ -63,14 +75,3 @@ var q = queue();

cleanup(layers);
function cleanup(layers) {
var parts = layers[0].split('/');
var tmp = parts[parts.indexOf('fixtures') + 1];
var tmpdir = layers[0].split(tmp)[0] + tmp;
rimraf(tmpdir, function(err) {
if (err) throw err;
t.end();
});
}
cleanup(layers, t);
});

@@ -87,14 +88,3 @@ });

cleanup(layers);
function cleanup(layers) {
var parts = layers[0].split('/');
var tmp = parts[parts.indexOf('fixtures') + 1];
var tmpdir = layers[0].split(tmp)[0] + tmp;
rimraf(tmpdir, function(err) {
if (err) throw err;
t.end();
});
}
cleanup(layers, t);
});

@@ -111,15 +101,57 @@ });

cleanup(layers);
cleanup(layers, t);
});
});
function cleanup(layers) {
var parts = layers[0].split('/');
var tmp = parts[parts.indexOf('fixtures') + 1];
var tmpdir = layers[0].split(tmp)[0] + tmp;
test('extract: options.dirname', function(t) {
fairy.extract(fixtures.valid.single_csv_withindex, { dirname: true }, function(err, output) {
if (err) throw err;
t.ok(output.length > 0, 'output has length');
t.ok(output.indexOf('fixtures') > -1, 'output has fixtures in path');
t.ok(output.indexOf('/') === 0, 'absolute path');
rimraf(output, function(err) {
if (err) throw err;
t.end();
});
});
});
rimraf(tmpdir, function(err) {
if (err) throw err;
t.end();
});
}
test('[bin] isBundle', function(t) {
var path = fixtures.valid.geojson_withindex_withmetadata;
exec('node ' + __dirname + '/../bin/bundle-fairy isBundle ' + path, function(err, stdout, stderr) {
if (err) t.fail();
t.equal(stderr, '', 'no stderr');
t.equal(stdout, 'true\n', 'stdout is true');
t.end();
});
});
test('[bin] extract', function(t) {
var path = fixtures.valid.geojson_withindex_withmetadata;
exec('node ' + __dirname + '/../bin/bundle-fairy extract ' + path, function(err, stdout, stderr) {
if (err) t.fail();
var layers = stdout.split(',');
t.equal(layers.length, 2, 'expected number of layers');
t.equal(stderr, '', 'no stderr');
t.ok(stdout.length > 0, 'stdout has length');
t.ok(stdout.indexOf(',') > -1, 'stdout has commas');
cleanup(layers, t);
});
});
test('[bin] extract --dirname flag', function(t) {
var path = fixtures.valid.geojson_withindex_withmetadata;
exec('node ' + __dirname + '/../bin/bundle-fairy extract ' + path + ' --d', function(err, stdout, stderr) {
if (err) t.fail();
t.equal(stderr, '', 'no stderr');
t.ok(stdout.length > 0, 'stdout has length');
t.ok(stdout.indexOf(',') === -1, 'stdout has no commas');
t.ok(stdout.indexOf('fixtures') > -1);
rimraf(stdout.replace('\n', ''), function(err) {
if (err) throw err;
t.end();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc