forked from EvanOxfeld/node-unzip
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom source option for Open (#223)
* Add Open.custom to provide unzipping from a custom source * Fix readme code block * Tweak readme for Open.custom * Update Open.custom example with Google Cloud Storage This better explains the use-case for using a custom source.
- Loading branch information
1 parent
fddad0a
commit 7f83183
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var unzip = require('../unzip'); | ||
var Promise = require('bluebird'); | ||
|
||
test("get content of a single file entry out of a zip", function (t) { | ||
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip'); | ||
|
||
var customSource = { | ||
stream: function(offset,length) { | ||
return fs.createReadStream(archive, {start: offset, end: length && offset+length}); | ||
}, | ||
size: function() { | ||
return new Promise(function(resolve, reject) { | ||
fs.stat(archive, function(err, d) { | ||
if (err) | ||
reject(err); | ||
else | ||
resolve(d.size); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
return unzip.Open.custom(customSource) | ||
.then(function(d) { | ||
var file = d.files.filter(function(file) { | ||
return file.path == 'file.txt'; | ||
})[0]; | ||
|
||
return file.buffer() | ||
.then(function(str) { | ||
var fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8'); | ||
t.equal(str.toString(), fileStr); | ||
t.end(); | ||
}); | ||
}); | ||
}); |