Comparing version 0.2.2 to 0.4.0
@@ -6,2 +6,3 @@ var fs = require('fs'); | ||
var walkdir = require('walkdir'); | ||
var minimatch = require('minimatch'); | ||
var mkdirp = require('mkdirp'); | ||
@@ -39,2 +40,6 @@ | ||
module.exports.createPackage = function(src, dest, cb) { | ||
module.exports.createPackageWithOptions(src,dest, {}, cb); | ||
} | ||
module.exports.createPackageWithOptions = function(src, dest, options, cb) { | ||
crawlFilesystem(src, function(err, filenames, metadata) { | ||
@@ -51,4 +56,8 @@ var filesystem = new Filesystem(src); | ||
else if ('file' === file.type) { | ||
files.push(filename); | ||
filesystem.insertFile(filename, file.stat); | ||
var shouldUnpack = false; | ||
if (options.unpack) | ||
shouldUnpack = minimatch(filename, options.unpack, {matchBase: true}); | ||
files.push({filename: filename, unpack: shouldUnpack}); | ||
filesystem.insertFile(filename, shouldUnpack, file.stat); | ||
} | ||
@@ -61,3 +70,3 @@ else if ('link' === file.type) { | ||
mkdirp.sync(path.dirname(dest)); | ||
disk.writeFilesystem(dest, filesystem, files, function() { | ||
@@ -76,3 +85,3 @@ if ('function' === typeof cb) | ||
var filesystem = disk.readFilesystem(archive); | ||
return disk.readFile(filesystem, filesystem.getFile(filename)); | ||
return disk.readFile(filesystem, filename, filesystem.getFile(filename)); | ||
}; | ||
@@ -86,3 +95,3 @@ | ||
var followLinks = 'win32' === os.platform(); | ||
mkdirp.sync(dest); // create destination directory | ||
@@ -116,3 +125,3 @@ | ||
// it's a file, extract it | ||
content = disk.readFile(filesystem, file); | ||
content = disk.readFile(filesystem, filename, file); | ||
fs.writeFileSync(destFilename, content); | ||
@@ -119,0 +128,0 @@ } |
@@ -1,6 +0,17 @@ | ||
var Filesystem = require('./filesystem'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var pickle = require('chromium-pickle'); | ||
var writeFileListToStream = function(out, list, cb) { | ||
var Filesystem = require('./filesystem'); | ||
var copyFileTo = function(dest, src, filename) { | ||
var content = fs.readFileSync(path.join(src, filename)); | ||
var targetFile = path.join(dest, filename); | ||
mkdirp.sync(path.dirname(targetFile)); | ||
fs.writeFileSync(targetFile, content); | ||
} | ||
var writeFileListToStream = function(dest, filesystem, out, list, cb) { | ||
if (list.length == 0) { | ||
@@ -14,4 +25,12 @@ out.end(); | ||
var src = fs.createReadStream(list[0]); | ||
src.on('end', writeFileListToStream.bind(this, out, list.slice(1), cb)); | ||
var file = list[0]; | ||
// the file should not be packed into archive. | ||
if (file.unpack) { | ||
copyFileTo(dest + '.unpacked', filesystem.src, path.relative(filesystem.src, file.filename)); | ||
return writeFileListToStream(dest, filesystem, out, list.slice(1), cb); | ||
} | ||
var src = fs.createReadStream(file.filename); | ||
src.on('end', writeFileListToStream.bind(this, dest, filesystem, out, list.slice(1), cb)); | ||
src.pipe(out, { end: false }); | ||
@@ -31,3 +50,3 @@ }; | ||
out.write(sizeBuf); | ||
out.write(headerBuf, writeFileListToStream.bind(this, out, files, cb)); | ||
out.write(headerBuf, writeFileListToStream.bind(this, dest, filesystem, out, files, cb)); | ||
}; | ||
@@ -61,5 +80,12 @@ | ||
module.exports.readFile = function(filesystem, info) { | ||
module.exports.readFile = function(filesystem, filename, info) { | ||
var buffer = new Buffer(info.size); | ||
if (info.size > 0) { | ||
if (info.size <= 0) | ||
return buffer; | ||
if (info.unpacked) { | ||
// it's an unpacked file, copy it. | ||
buffer = fs.readFileSync(path.join(filesystem.src + '.unpacked', filename)); | ||
} | ||
else { | ||
// Node throws an exception when reading 0 bytes into a 0-size buffer, | ||
@@ -66,0 +92,0 @@ // so we short-circuit the read in this case. |
@@ -32,3 +32,10 @@ var fs = require('fs'); | ||
Filesystem.prototype.insertFile = function(p, stat) { | ||
Filesystem.prototype.insertFile = function(p, shouldUnpack, stat) { | ||
var node = this.searchNodeFromPath(p); | ||
if (shouldUnpack) { | ||
node.size = stat.size; | ||
node.unpacked = true; | ||
return; | ||
} | ||
// JavaScript can not precisely present integers >= UINT32_MAX. | ||
@@ -38,3 +45,2 @@ if (stat.size > 4294967295) | ||
var node = this.searchNodeFromPath(p); | ||
node.size = stat.size; | ||
@@ -41,0 +47,0 @@ node.offset = this.offset.toString(); |
@@ -5,3 +5,3 @@ { | ||
"description": "Creating atom-shell app packages", | ||
"version": "0.2.2", | ||
"version": "0.4.0", | ||
"bin": { | ||
@@ -33,2 +33,3 @@ "asar": "bin/asar" | ||
"cuint": "0.1.5", | ||
"minimatch": "2.0.4", | ||
"mkdirp": "^0.5.0", | ||
@@ -35,0 +36,0 @@ "walkdir": "0.0.7" |
@@ -11,3 +11,3 @@ 'use strict'; | ||
describe('api', function() { | ||
it('should create archive from directory', function(done) { | ||
@@ -45,2 +45,8 @@ asar.createPackage('test/input/packthis/', 'tmp/packthis-api.asar', function (error) { | ||
it('should extract a binary file from archive with unpacked files', function() { | ||
var actual = asar.extractFile('test/input/extractthis-unpack.asar', 'dir2/file2.png'); | ||
var expected = fs.readFileSync('test/expected/extractthis/dir2/file2.png', 'utf8'); | ||
return assert.equal(actual, expected); | ||
}); | ||
it('should extract an archive', function(done) { | ||
@@ -51,2 +57,7 @@ asar.extractAll('test/input/extractthis.asar','tmp/extractthis-api/'); | ||
it('should extract an archive with unpacked files', function(done) { | ||
asar.extractAll('test/input/extractthis-unpack.asar','tmp/extractthis-unpack-api/'); | ||
compDirs('tmp/extractthis-api/', 'test/expected/extractthis', done); | ||
}); | ||
}); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
describe('command line interface', function() { | ||
it('should create archive from directory', function(done) { | ||
@@ -21,2 +21,10 @@ exec('node bin/asar p test/input/packthis/ tmp/packthis-cli.asar', function (error, stdout, stderr) { | ||
it('should create archive from directory with unpacked files', function(done) { | ||
exec('node bin/asar p test/input/packthis/ tmp/packthis-unpack-cli.asar --unpack *.png', function (error, stdout, stderr) { | ||
var actual = fs.readFileSync('tmp/packthis-unpack-cli.asar', 'utf8'); | ||
var expected = fs.readFileSync('test/expected/packthis-unpack.asar', 'utf8'); | ||
done(assert.equal(actual, expected)); | ||
}); | ||
}); | ||
it('should list files/dirs in archive', function(done) { | ||
@@ -33,2 +41,13 @@ exec('node bin/asar l test/input/extractthis.asar', function (error, stdout, stderr) { | ||
it('should list files/dirs in archive with unpacked files', function(done) { | ||
exec('node bin/asar l test/input/extractthis-unpack.asar', function (error, stdout, stderr) { | ||
var actual = stdout; | ||
var expected = fs.readFileSync('test/expected/extractthis-filelist.txt', 'utf8') + '\n'; | ||
// on windows replace slashes with backslashes and crlf with lf | ||
if ('win32' === os.platform()) | ||
expected = expected.replace(/\//g, '\\').replace(/\r\n/g, '\n'); | ||
done(assert.equal(actual, expected)); | ||
}); | ||
}); | ||
// we need a way to set a path to extract to first, otherwise we pollute our project dir | ||
@@ -63,2 +82,8 @@ // or we fake it by setting our cwd, but I don't like that | ||
it('should extract an archive with unpacked files', function(done) { | ||
exec('node bin/asar e test/input/extractthis-unpack.asar tmp/extractthis-unpack-cli/', function (error, stdout, stderr) { | ||
compDirs('tmp/extractthis-unpack-cli/', 'test/expected/extractthis', done); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27347
29
463
6
+ Addedminimatch@2.0.4
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedminimatch@2.0.4(transitive)