-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use yazl
instead of JSZip
#42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var gutil = require('gulp-util'); | ||
var unzip = require('decompress-unzip'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thejoshwolfe has https://github.com/thejoshwolfe/yauzl as well, just sayin' :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrewrk, look what library I'm using in decompress-unzip :). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hahahaha |
||
var vinylAssign = require('vinyl-assign'); | ||
var zip = require('./'); | ||
|
||
it('should zip files', function (cb) { | ||
var stream = zip('test.zip'); | ||
var i = 0; | ||
var unzipper = unzip(); | ||
var stats = fs.statSync(__dirname + '/fixture/fixture.txt'); | ||
var files = []; | ||
|
||
unzipper.on('data', files.push.bind(files)); | ||
unzipper.on('end', function () { | ||
assert.equal(files[0].path, 'fixture.txt'); | ||
assert.equal(files[1].path, 'fixture2.txt'); | ||
assert.equal(files[0].contents.toString(), 'hello world'); | ||
assert.equal(files[1].contents.toString(), 'hello world 2'); | ||
assert.equal(files[0].stat.mode, stats.mode); | ||
assert.equal(files[1].stat.mode, stats.mode); | ||
cb(); | ||
}); | ||
|
||
stream.on('data', function (file) { | ||
i++; | ||
assert.equal(path.normalize(file.path), path.join(__dirname, 'fixture/test.zip')); | ||
assert.equal(file.relative, 'test.zip'); | ||
assert(file.contents.length > 0); | ||
}); | ||
|
||
stream.on('end', function () { | ||
assert(i === 1); | ||
cb(); | ||
}); | ||
|
||
stream.write(new gutil.File({ | ||
cwd: __dirname, | ||
base: __dirname + '/fixture', | ||
path: __dirname + '/fixture/fixture.txt', | ||
contents: new Buffer('hello world'), | ||
stat: { | ||
mtime: new Date() | ||
mode: stats.mode, | ||
mtime: stats.mtime | ||
} | ||
})); | ||
|
||
|
@@ -36,9 +47,11 @@ it('should zip files', function (cb) { | |
path: __dirname + '/fixture/fixture2.txt', | ||
contents: new Buffer('hello world 2'), | ||
stat: { | ||
mtime: new Date() | ||
mode: stats.mode, | ||
mtime: stats.mtime | ||
} | ||
})); | ||
|
||
stream.pipe(vinylAssign({extract:true})).pipe(unzipper); | ||
stream.end(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't have to wait until the end callback to pipe the output stream. in fact, you can skip the zip.end function entirely - it's just to notify you when it knows the final size of the zip file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think it's needed. I get timeout issues otherwise when running tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry, you do need to call it. but you don't need to wait for the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from https://github.com/thejoshwolfe/yazl#outputstream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes no difference in speed or whatsoever though since we're only handling one buffer at a time.