Comparing version 0.0.2 to 0.0.3
37
index.js
@@ -17,3 +17,4 @@ /*jshint esnext: true */ | ||
var fs = require('fs'); | ||
var tgz = require('tar.gz'); | ||
var tarball = require('tar-fs'); | ||
var gunzip = require('gunzip-maybe'); | ||
var Zip = require('adm-zip'); | ||
@@ -59,2 +60,3 @@ var glob = require('glob'); | ||
* @param {Stream} write | ||
* @param {string} [closeEvent] - close event name to watch, default 'close' | ||
* @returns {{ err: {Error}, done: {boolean} }} | ||
@@ -64,3 +66,3 @@ * @access private | ||
*/ | ||
function pipeSync (read, write) { | ||
function pipeSync (read, write, closeEvent) { | ||
'use strict'; | ||
@@ -71,2 +73,4 @@ | ||
closeEvent = closeEvent || 'close'; | ||
read.on('error', function (e) { | ||
@@ -91,3 +95,3 @@ err = e; | ||
write.on('close', function (e) { | ||
write.on(closeEvent, function (e) { | ||
err = e; | ||
@@ -794,5 +798,6 @@ done = true; | ||
var dir = p.dirname(dst); | ||
var stat = exists(src); | ||
var existingSrc = exists(src); | ||
var root = ''; | ||
if (!stat) { | ||
if (!existingSrc) { | ||
lastError = new Error('Tar error: source path "' + src + | ||
@@ -807,4 +812,13 @@ '" does not exists!'); | ||
if (existingSrc.isDirectory()) { | ||
root = p.basename(src) + '/'; | ||
} | ||
return pipeSync( | ||
tgz().createReadStream(src), | ||
tarball.pack(src, { | ||
map: function (header) { | ||
header.name = root + header.name; | ||
return header; | ||
} | ||
}).pipe(gunzip()), | ||
fs.createWriteStream(dst) | ||
@@ -831,5 +845,5 @@ ); | ||
var dir = p.dirname(dst); | ||
var stat = exists(src); | ||
var existingSrc = exists(src); | ||
if (!stat) { | ||
if (!existingSrc) { | ||
lastError = new Error('Untar error: source path "' + src + | ||
@@ -845,4 +859,5 @@ '" does not exists!'); | ||
return pipeSync( | ||
fs.createReadStream(src), | ||
tgz().createWriteStream(dst) | ||
fs.createReadStream(src).pipe(gunzip()), | ||
tarball.extract(dst), | ||
'finish' | ||
); | ||
@@ -1260,2 +1275,4 @@ } | ||
relpath: relpath, | ||
basename: p.basename, | ||
dirname: p.dirname, | ||
glob: glob.sync, | ||
@@ -1262,0 +1279,0 @@ DIRSEP: SEP, |
{ | ||
"name": "fs-cli", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Easy filesystem functions", | ||
@@ -13,3 +13,4 @@ "main": "index.js", | ||
"generate-docs": "jsdoc -c .jsdocrc --verbose", | ||
"jscheck": "jshint index.js && jscs index.js" | ||
"jscheck": "jshint index.js cover.js && jscs index.js cover.js", | ||
"prepublish": "npm run jscheck && npm test && npm run generate-docs" | ||
}, | ||
@@ -21,8 +22,10 @@ "license": "ISC", | ||
"glob": "^6.0.1", | ||
"tar.gz": "^1.0.2" | ||
"gunzip-maybe": "^1.2.1", | ||
"tar-fs": "^1.8.1" | ||
}, | ||
"devDependencies": { | ||
"loke-jsdoc-theme": "^2.1.0", | ||
"mocha": "^2.3.4" | ||
"mocha": "^2.3.4", | ||
"tar-stream": "^1.3.1" | ||
} | ||
} |
@@ -85,3 +85,5 @@ # Easy FS Scripting With NodeJS | ||
- **exists**: checks if exists, return file system object stats if exists | ||
- **relpath/realpath**: paths transform, cross-platform, exists-free | ||
- **relpath/realpath**: paths transform, cross-platform, exists-free | ||
- **basename/dirname**: aliases for native path.basename/path.dirname | ||
- **glob**: alias for glob.sync | ||
@@ -88,0 +90,0 @@ ## Want More? |
var assert = require('assert'); | ||
var fs = require('../index'); | ||
var tgz = require('tar.gz'); | ||
var tar = require('tar-stream'); | ||
var gunzip = require('gunzip-maybe'); | ||
var nfs = require('fs'); | ||
var p = require('path'); | ||
@@ -15,3 +17,3 @@ | ||
it('should create zip archive', function () { | ||
it('should create gzipped tarball', function () { | ||
assert.equal(fs.tar(src, dst), true); | ||
@@ -28,16 +30,18 @@ assert.equal(!!fs.exists(dst), true); | ||
it('should contain certain file', function (done) { | ||
var extract = tar.extract(); | ||
var found = false; | ||
var read = require('fs').createReadStream(dst); | ||
var parse = tgz().createParseStream(); | ||
var thisFile = p.basename(__filename); | ||
parse.on('entry', function(entry){ | ||
var entryFile = p.basename(entry.path); | ||
if (entryFile == thisFile) { | ||
extract.on('entry', function (header, stream, next) { | ||
if (header.name == 'test/tar.js') { | ||
found = true; | ||
stream.end(); | ||
extract.end(); | ||
done(); | ||
} | ||
stream.on('end', next); | ||
stream.resume(); | ||
}); | ||
parse.on('close', function () { | ||
extract.on('finish', function () { | ||
assert.equal(found, true); | ||
@@ -47,3 +51,5 @@ done(); | ||
read.pipe(parse); | ||
nfs.createReadStream('./tmp/test.tgz') | ||
.pipe(gunzip()) | ||
.pipe(extract); | ||
}); | ||
@@ -50,0 +56,0 @@ |
@@ -15,14 +15,6 @@ var assert = require('assert'); | ||
}); | ||
/** | ||
* Currenty there is some strange behavior of tar.gz library | ||
* At least on Windows its write stream fires "close" event, but | ||
* as may be seen from this test writing the files to disk | ||
* is not actually finished! This requires for further deeper investigation | ||
* or maybe own implementation of packing/unpacking tarballs | ||
* @TODO: investigate and fix tar/untar behavior | ||
*/ | ||
/*it('destination should have correct list of files', function () { | ||
it('destination should have correct list of files', function () { | ||
assert.deepEqual(fs.ls('./test').sort(), fs.ls('./tmp/test').sort()); | ||
assert.equal(fs.error(), null); | ||
});*/ | ||
}); | ||
@@ -29,0 +21,0 @@ after(function() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1824563
2686
114
5
3
+ Addedgunzip-maybe@^1.2.1
+ Addedtar-fs@^1.8.1
+ Addedbl@1.2.3(transitive)
+ Addedbrowserify-zlib@0.1.4(transitive)
+ Addedbuffer-alloc@1.2.0(transitive)
+ Addedbuffer-alloc-unsafe@1.1.0(transitive)
+ Addedbuffer-fill@1.0.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedduplexify@3.7.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedgunzip-maybe@1.4.2(transitive)
+ Addedis-deflate@1.0.0(transitive)
+ Addedis-gzip@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedpako@0.2.9(transitive)
+ Addedpeek-stream@1.1.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpump@1.0.32.0.1(transitive)
+ Addedpumpify@1.5.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstream-shift@1.0.3(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtar-fs@1.16.4(transitive)
+ Addedtar-stream@1.6.2(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedto-buffer@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedtar.gz@^1.0.2
- Removedblock-stream@0.0.9(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfstream@1.0.12(transitive)
- Removedglob@7.2.3(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedmout@0.11.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedtar@2.2.2(transitive)
- Removedtar.gz@1.0.7(transitive)