cthackers / adm-zip Goto Github PK
View Code? Open in Web Editor NEWA Javascript implementation of zip for nodejs. Allows user to create or extract zip files both in memory or to/from disk
License: MIT License
A Javascript implementation of zip for nodejs. Allows user to create or extract zip files both in memory or to/from disk
License: MIT License
Hi,
We use your compression lib in build processes. These are all non async and they output the entry name due to this line:
https://github.com/cthackers/adm-zip/blob/master/zipEntry.js#L115
Would have been nice to be able to disable it or maybe even remove that line?
Trying to unzip to a folder that doesn't yet exist results in some path mess. This is what I'm doing:
zip.extractAllTo('dist/tmp/' + index + '/');
Produces this error:
fs.js:381
return binding.mkdir(pathModule._makeLong(path),
^
Error: ENOENT, no such file or directory '/Users/jza/dev/jquery-ui/dist/tmp/0/development-bundle/ui\/Users/jza/dev/jquery-ui/dist/tmp/0/development-bundle/ui'
at Object.mkdirSync (fs.js:381:18)
at /Users/jza/dev/adm-zip/util/utils.js:19:20
at Array.forEach (native)
at mkdirSync (/Users/jza/dev/adm-zip/util/utils.js:12:26)
at Object.writeFileTo (/Users/jza/dev/adm-zip/util/utils.js:96:17)
at /Users/jza/dev/adm-zip/adm-zip.js:346:23
at Array.forEach (native)
at Object.extractAllTo (/Users/jza/dev/adm-zip/adm-zip.js:340:26)
at [object Object].<anonymous> (/Users/jza/dev/jquery-ui/grunt.js:499:8)
at [object Object].emit (events.js:88:20)
Not the messed up path.
Hi.
I need to zip a directory, say, [test] to make a node.js runnable
The directory looks like
test\package.json, etc....
test\include1\ -- bunch of directories and files in here that all need be zipped
say,
test\include1\file1.txt
test\include1\dir1\file2.txt
test\exclude1\ -- bunch of directories files in here. this shouldn't be zipped.
To do this with addLocalFolder, I'd call addLocalFolder('test'), but this won't be good since 'exclude1' get zipped too and has to be delted
And it seems that i can't really use addLocalFile since it ignores the path...
(for example, test\include1\file1.txt will be zipped as 'file1.txt' at the top level...
Am I missing something here?
I'm thinking addLocalFolder should take an 'exclude pattern' parameter or addLocalFile should have a way that it keeps the path in the zip file..
Hi.
I tried to use the latest version v0.4.3 of adm-zip to open an existing ZIP archive , add some new files via zip.addFile() and save the complete zip back to disk as a new file by providing a new path+filename.
But everytime the function zip.writeZip('/path/newfile.zip') crashes. The only information I get is an "undefined" string in the console.
I use arm-zip with Node.js v0.8.8. Is this a problem?
Either Korean, Japanese, adm-zip fails with Invalid CEN header (bad signature)
message.
Any way to fix it?
I want to remove the unnecessary files from archives, but adm-zip#deleteFile is not work and can't delete entry.
Please, sync published version state with github sourses
PS. If you like make
- here is example, that protects from unsync mistakes https://github.com/nodeca/argparse/blob/master/Makefile#L82
Opening a 600 MB ZIP file with:
var zip = new AdmZip('600MB.zip');
will cause node.js on Windows to exit abnormally with exit code %ERRORLEVEL% of 3.
I am using a Windows 7 Ultimate 64 bit machine with node.js v 0.6.13
When i rename a .docx file into a .zip file and try to open it via adm-zip, most of the methods like .getEntries() and .readAsText() work.
When I use .extractAllTo() however I am hit with the following.
zip.extractAllTo('./out', true)
'./out', true)
Error: oob
at Buffer.slice (buffer.js:517:26)
at decompress (R:\xampp\htdocs\phpdocx\experiment\node_modules\adm-zip\zipEntry.js:39:73)
at Object.getData (R:\xampp\htdocs\phpdocx\experiment\node_modules\adm-zip\zipEntry.js:193:13)
at R:\xampp\htdocs\phpdocx\experiment\node_modules\adm-zip\adm-zip.js:344:37
at Array.forEach (native)
at Object.extractAllTo (R:\xampp\htdocs\phpdocx\experiment\node_modules\adm-zip\adm-zip.js:342:26)
at repl:1:6
at REPLServer.eval (repl.js:80:21)
at Interface. (repl.js:182:12)
at Interface.emit (events.js:67:17)undefined
currently says
git://github.com/[email protected]:cthackers/adm-zip.git
It's probably easier to just put the https address
When writing a zip file I noticed that each part of the entry is logged. Not a big deal, but should be removed probably.
in adm-zip.js, line 296:
maintainEntryPath = typeof maintainEntryPath == "undefned" ? true : maintainEntryPath;
you mistyped "undefined" with "undefned"
I zipped a folder in Ubuntu 11.10 64bit.
I tried to use getEntry function to get file content but got checksum failed
error.
How can I help you to investigate the problem?:)
extractEntryTo should be able to extract to an existing folder.
Working on build scripts for jQuery UI, I'm getting a 'crc32 checksum failed' error on a otherwise valid zip file. Extracting that file with unzip
or the built-in OSX utility works fine.
To get a copy of the zip file in question, go to http://jqueryui.com/download and click Download on the right side.
Here's my simple script to test this:
var AdmZip = require('adm-zip');
var fs = require('fs');
fs.mkdirSync('tmp');
var zip = new AdmZip('jquery-ui-1.8.18.custom.zip');
zip.extractAllTo('tmp');
The mkdirSync call is necessary due to #2.
Before outputting the error the script actually manages to extract the index.html file.
Trying to extract a zip file to a directoy that doesn't exist yet fails:
TypeError: Cannot call method 'makeDir' of undefined
at Object.writeFileTo (/Users/jza/dev/zip-test/node_modules/adm-zip/util/utils.js:77:31)
Changing exports.Utils.makeDir
to module.exports.makeDir
just causes another error, apparently the path resolving in mkdirSync
is buggy.
adm-zip deflate some binary file with a bad crc.
This files can't be inflate with 3th part software (as 7z).
I'm using windows 7 64 bit.
node v0.10.13
This is my simple script:
var AdmZip = require('adm-zip');
var zip = new AdmZip();
zip.addLocalFile("./input_image3.jpg", "/");
zip.writeZip("test.zip");
In Linux, I compressed a program file [Type: executable(application/x-executable) ].
After I extract it , the file is no longer a executable program.
I am currently writing on a tool to unzip archives using your module and I just recognised the very heavy usage of RAM.
To extract an archive of about 11MB, my node.exe uses about 250MB of RAM.
I experienced this with Node v0.10.5 on different machines running Windows7 or Windows8 using different archives of nearly the same size in total (might have been a few KB more or less on different archives), and with files of different filesizes within the archives (between 1KB and 1.8MB per file), the RAM-usage has always been nearly the same.
My code:
var AdmZip = require('adm-zip');
var archivePath = 'any-path.zip';
var extractPath = 'another-path';
var zip = new AdmZip(archivePath);
zip.extractAllTo(extractPath);
i am beginner in javascript.
I have a phonegap application which will need to take a zip archive of a webpage, unzip it, and display the output.
Anyone tell me how to use this plugin??
Thank for reading
for example, when direcory's name contains chinese, korean....
Did you have any plan to add 'http://www.nodejs.org/api/zlib.html' support?
Hi
your package.json say current version is 0.1.9
According to npm and versioneye
https://www.versioneye.com/package/npm--adm-zip
it is 0.2.0
cheers Martin
Please update this.
Tried unzipping a 64MB zip file, the following error was thrown:
FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
I used adm-zip to produce a zip archive ( I changed the code to only store the files, no compression ). but the output is invalid:
var zip = new AdmZip();
zip.addFile('node_modules/test/index.js','console.log("me")');
var out = path.resolve("./test3.zip");
zip.writeZip(out);
here is the generated output.
Similar to this issue, I am getting a CRC32 checksum failed
error while trying to unzip this file. I have the latest [email protected] version installed.
Extracting that file with unzip or the built-in OSX utility works fine.
Similar to the previous issue, here is the code to reproduce the error:
var AdmZip = require('adm-zip');
var fs = require('fs');
fs.mkdirSync('tmp');
var zip = new AdmZip('205555.zip');
zip.extractAllTo('tmp');
Note that the old issue has been fixed when I run it on my machine (that is, the jquery-ui-1.8.18.custom.zip can be now fully extracted).
Trying to compress a folder, this is my test script:
var AdmZip = require('adm-zip');
var zip = new AdmZip();
zip.addLocalFolder('./dist');
zip.writeZip('./output.zip');
The dist
folder contains a few files. The script runs without errors and outputs a output.zip
file in the right location. Trying to decompress that with the built-in tool on OSX, the only output I get is a output.zip.cpgz
file. Trying to uncompress that yields a output 2.zip
, which again produces a cpgz file and so forth.
Can't tell what I'm missing, so hoping for help here. Let me know if you need specific information or a copy of the output.
using Node v 0.8.2 and adm-zip 0.1.5, and following the tutorial in the README, I am currently unable to zip when using buffers to add entries to the archive:
var AdmZip = require('adm-zip');
undefined
var zip = new AdmZip();
undefined
zip.addFile("test.txt", new Buffer("inner content of the file"), "entry comment goes here");
undefined
zip.writeZip('/private/tmp/example.zip')
undefined
/private/tmp $ unzip example.zip
Archive: example.zip
inflating: test.txt
error: invalid compressed data to inflate
I don't see many documented callbacks? How would I get an asynchronous completion notification on operations?
Really liking this module otherwise, keen to use it.
I am currently unable to figure out how to get files unpacked to a windows UNC folder path. Everything including the node server is Windows.
Files of subfolders are folders instead of files in zip file
package.json
{ "name": "test", "version": "0.1.0", "devDependencies": { "adm-zip": "0.1.4" } }
src/test.txt:
hello world
grunt.js:
module.exports = function( grunt ) { grunt.initConfig({ zip: { dist: { src: 'src/**/*', dest: 'test.zip' } } }); grunt.registerMultiTask( 'zip', 'Create a zip file', function() { var files = grunt.file.expandFiles( this.file.src ); grunt.log.writeln( 'Creating zip file ' + this.file.dest ); var fs = require( 'fs' ); var AdmZip = require( 'adm-zip' ); var zip = new AdmZip(); files.forEach( function( file ) { grunt.verbose.writeln( 'Zipping ' + file ); zip.addFile( file, fs.readFileSync( file ) ); }); zip.writeZip( this.file.dest ); grunt.log.writeln( 'Wrote ' + files.length + ' files to ' + this.file.dest ); }); grunt.registerTask( 'default', 'zip' ); };
test.zip:
- src |- test.txt (folder instead of file)
EDIT: added this code after line 249 in adm-zip.js:
console.log(entry.toString());
and got this output:
{ "entryName" : "src/test.txt", "name" : "test.txt", "comment" : "", "isDirectory" : false, "header" : { "made" : 10, "version" : 10, "flags" : 0, "method" : STORED (0), "time" : 1080181346, "crc" : 0x8BD69E52, "compressedSize" : 11 bytes, "size" : 11 bytes, "fileNameLength" : 12, "extraLength" : 0 bytes, "commentLength" : 0 bytes, "diskNumStart" : 0, "inAttr" : 438, "attr" : 438, "offset" : 0, "entryHeaderSize" : 58 bytes }, "compressedData" : "data" : <11 bytes buffer> }
Similar to issues #12, #13, and #15 , I'm getting repeating characters on simple text files I'm extracting. The repeating character changes on each file. I even tried the readAsText method, and it's showing the same issue.
You can get the zip file here.
(also, I noticed this as well path.existsSync is now called fs.existsSync
.. it didn't cause a real issue, more of a warning)
on build v0.1.9 and node v0.8.21
I'm unzipping a 23KB zip file like this:
var zip = new AdmZip(zipBuffer);
zip.readAsText("actors.xml");
But the output ends with a repeating a
like this:
<BannerPath>graphical/79349-g17.jpg</BannerPath>\n <BannerType>series</BannerType>\n <BannerType2>graphical</BannerType2>\n <Language>en</Language>\n <Rating>1.0000</Rating>\n <RatingCount>2</RatingCount>\n</Banner>\n<Banner>\n <id>90161111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
or like this:
<SortOrder>3</SortOrder>\n</Actor>\n<Actor>\n <id>130301</id>\n <Image>actors/130301.jpg</Image>\n <Name>John Lithgaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
It happens to two different files in the same zip.
adm-zip can create and extract from it's own zip files but if I try to extract the files by using venerable WinRar I get a CRC error:
! D:\tsd\tsd-origin\repo\repository_v2.zip: CRC failed in repository_v2.json. The file is corrupt
This is on Windows Vista 64 using node v0.10.10 and adm-zip 0.4.3 from NPM.
For me the node.js compression example on ''ADM-ZIP-Introduction' on the wiki produces readable zip but with an empty folder named 'test.txt' instead of the 'test.txt' file.
I got adm-zip from npm today, it's package.json says 0.1.8 and this was on windows vista 64bit, my node.js is 0.8.14 x64 and I unzip using good ol' WinRar.
My code:
var zip = new Zip();
zip.addFile("test.txt", new Buffer("inner content of the file"), "entry comment goes here");
zip.writeZip(path + '/package.zip');`
A ZIP containing files created with extra fields present in their local file header (such as universal time, and Unix UID/GID) cannot be properly extracted with extractEntryTo or extractAllTo methods.
I believe the fix is to replace the following line in zipFile.js:
entry.setCompressedData(buf.slice(entry.header.offset, entry.header.offset + Utils.Constants.LOCHDR + entry.header.compressedSize + entry.entryName.length));
with:
entry.setCompressedData(buf.slice(entry.header.offset, entry.header.offset + Utils.Constants.LOCHDR + entry.header.compressedSize + entry.entryName.length + buf.readUInt16LE(entry.header.offset + Utils.Constants.LOCEXT)));
Hi, i've just used the ZIP creation tutorial code found on the README and just wanted to tell that it still outputs a notice on the console.log:
"path.existsSync is now called `fs.existsSync`."
I guess it's:
https://github.com/cthackers/adm-zip/blob/master/util/fattr.js#L24
https://github.com/cthackers/adm-zip/blob/master/util/utils.js#L100
maybe there are some bugs in compress or packHeader
jszip doesn't really support nodejs (though its can run with some small modifications), but they've got a comprehensive testsuite: https://github.com/Stuk/jszip/tree/master/test
Considering the compability problems adm-zip had (and still has?), their testsuite might be a good starting point.
He also gathered some specs: https://github.com/Stuk/jszip/tree/master/docs
Looks like the Wiki page for your documentation is incorrect:
https://github.com/cthackers/adm-zip/wiki/ADM-ZIP#adm-zip-constructorstring-filepath--
It lists the contstructor as new Zip()
rather than AdmZip()
.
Running my grunt build mechanism won't create a zip file...
package.json:
{ "name": "test", "version": "0.1.0", "devDependencies": { "adm-zip": "0.1.4" } }
grunt.js:
module.exports = function( grunt ) { grunt.initConfig({ zip: { dist: { src: 'test.txt', dest: 'test.zip' } } }); grunt.registerMultiTask( 'zip', 'Create a zip file', function() { var files = grunt.file.expandFiles( this.file.src ); grunt.log.writeln( 'Creating zip file ' + this.file.dest ); var fs = require( 'fs' ); var AdmZip = require( 'adm-zip' ); var zip = new AdmZip(); files.forEach( function( file ) { grunt.verbose.writeln( 'Zipping ' + file ); zip.addFile( file, fs.readFileSync( file ) ); }); zip.writeZip( this.file.dest ); grunt.log.writeln( 'Wrote ' + files.length + ' files to ' + this.file.dest ); }); grunt.registerTask( 'default', 'zip' ); };
test.txt:
Hello world
Output on running grunt -v
:
Initializing Command-line options: --verbose Registering built-in tasks. Loading "concat.js" tasks and helpers...OK Tasks: concat Helpers: concat Loading "init.js" tasks and helpers...OK Tasks: init Helpers: prompt, prompt_for_obj, prompt_for, git_origin, github_web_url Loading "lint.js" tasks and helpers...OK Tasks: lint Helpers: lint Loading "min.js" tasks and helpers...OK Tasks: min Helpers: uglify, gzip, min_max_info Loading "misc.js" tasks and helpers...OK Helpers: config, json, strip_banner, file_strip_banner, banner Loading "qunit.js" tasks and helpers...OK Tasks: qunit Loading "server.js" tasks and helpers...OK Tasks: server Loading "test.js" tasks and helpers...OK Tasks: test Loading "watch.js" tasks and helpers...OK Tasks: watch Reading "grunt.js" config file...OK Initializing config...OK Loading "grunt.js" tasks and helpers...OK Tasks: zip, default No tasks specified, running default tasks. Running tasks: default Running "default" task Running "zip" task Running "zip:dist" (zip) task Verifying property zip.dist exists in config...OK Creating zip file test.zip Zipping test.txt Wrote 1 files to test.zip Done, without errors.
But there's no test.zip - nowhere...
I keep running into an issue where the zip files I create are unable to be unzipped without CRC errors. I am creating an XML file from JSON which I am then trying to zip and email. Each part of this process is all being done in buffer. At no point have I written anything out to disk yet. When the XML files are small (read: less than 1k in size), there's no problem. Once the XML files start to get bigger in size, every zip file has an invalid CRC and can't be extracted properly without corruption.
I can't narrow down where the problem might be, except for maybe the size issue as that's the only time there's a change in the file that's being zipped where I've seen the CRC error occur.
Hey -- I'm ending up with corrupted PNG files when I use adm-zip, since PNGs are already in effect compressed. When I unzip the file that adm-zip crates, my PNGs are zero bytes.
:(
Essentially I'd like to include the PNG in the archive but not actually compress it. Possible?
Right now I'm just using addLocalFolder to add my src directory
I'm building apps for samsung TVs, so everything needs to be inside of one zip file for the platform to decompress.
thanks!!
I'm writing an app that needs to deal with zip files recursively nested within zip files. It would be great to be able to inflate the buffer in memory to get another buffer and then pass the inflated buffer to another call to new Zip(...) so that I can recursively unzip files all within memory, without needed any disk I/O.
It looks like the latest source in GitHub has the ability to do this, but it's not published on NPM. Is support for this planned? Will it be available in NPM soon?
Thanks! And thanks for a very useful library.
Dave
I get:
Unable to unarchive "filename.zip" into "dest_folder". (Error 1 - Operation not permitted)
When trying to auto-extract resulting archive onclick in Mac OS X.
When doing the deflate in an async process, the results of each deflate of a chunk are returned to the callback instead of combining the chunks and then returning the full deflated buffer
I have a zip archive:
directory images contains 1 image file
directory css contains 2 css files
directory js - empty
index.html
when I tried unzip this archive with extractAllTo I lost a directory js
https://github.com/cthackers/adm-zip/blob/master/adm-zip.js#L371
The callback method doesn't seem to be called or error or result.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.