Git Product home page Git Product logo

cross-zip's Introduction

cross-zip ci npm downloads javascript style guide

Cross-platform .zip file creation

install

npm install cross-zip

usage

var zip = require('cross-zip')

var inPath = path.join(__dirname, 'myFolder') // folder to zip
var outPath = path.join(__dirname, 'myFile.zip') // name of output zip file

zip.zipSync(inPath, outPath)

api

zip.zip(inPath, outPath, [callback])

Zip the folder at inPath and save it to a .zip file at outPath. If a callback is passed, then it is called with an Error or null.

zip.zipSync(inPath, outPath)

Sync version of zip.zip.

zip.unzip(inPath, outPath, [callback])

Unzip the .zip file at inPath into the folder at outPath. If a callback is passed, then it is called with an Error or null.

zip.unzipSync(inPath, outPath)

Sync version of zip.unzip.

Windows users

This package requires .NET Framework 4.5 or later and Powershell 3. These come pre-installed on Windows 8 or later.

On Windows 7 or earlier, you will need to install these manually in order for cross-zip to function correctly.

reference

related

license

MIT. Copyright (c) Feross Aboukhadijeh.

cross-zip's People

Contributors

chalker avatar fanatid avatar feross avatar greenkeeper[bot] avatar greenkeeperio-bot avatar inukshuk avatar malept avatar marshallofsound avatar max-mapper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cross-zip's Issues

Only .* files are added to zip on Windows

When used on windows with path ./ only files starting with . are added to the zip file instead of the whole folder.
Probably because of the command used for windows:
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('${inPath}', '${outPath}'); }"

How to compress files without including their parent folder?

I'm not sure if this is a bug or intended behavior, but in my app I'm using both unzip and zip to first unpack a zip file, then modify its contents, and finally zip all the files again.

Since unzip takes a zip file containing files ./a.txt and ./b.txt and puts them into the directory ./example, I expected zip to take the files ./example/a.txt and ./example/a.txt and put them into the zip file as ./a.txt and ./b.txt. That's not the case, however, as the ./example directory is included in the zip file and there's seemingly no way to put files at the root of the zip file (and recreate the original zip).

Is there a way to do this? (I'm using cross-zip v2.1.6 on Linux.)

Using unzip produces cb(err)

Using unzip as documented produces the following message after completion. I was able to correct the error by adding a callback as a third parameter for the unzip. Is this just missing in the documentation, or is there a better way to make it work?

Original Code

var zip = require('cross-zip'); zip.unzip('./test.zip', './tmp');

Produces:

C:\Users\Paul\AppData\Roaming\npm\node_modules\cross-zip\index.js:87
cb(err)
^

TypeError: cb is not a function
at C:\Users\Paul\AppData\Roaming\npm\node_modules\cross-zip\index.js:87:5
at ChildProcess.exithandler (child_process.js:194:7)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:817:16)
at Socket. (internal/child_process.js:319:11)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Pipe._onclose (net.js:469:12)

Correct and Functional Code

var zip = require('cross-zip'); zip.unzip('./test.zip', './tmp', function() { console.log("done"); });

Produces:

done

Windows - Zip cannot be opened by Chrome Browser or Mozilla Addons Store

Hi,

I'm using cross-zip on Windows 10 and I'm experiencing an issue where it believes the file is "corrupted" in certain situations.

The zips are creating using an NPM script, so I have both cross-zip and cross-zip-cli installed:

cross-var cross-zip build dist/$npm_package_name-$npm_package_version.production.zip

The zip is created in the directory but I get the following issues when trying to use the zip:

  • image

  • I also get the following error message from Chrome when trying to drag and drop the zip into the chrome://extensions page: "Failed to load extension from: <path>. Could not unzip extension for install."

There was a suggestion, in an issue on the Mozilla Addons repository, that it could relate to the behaviour of the System.IO.Compression.ZipFile class.

Do you know if there is anything that can be done?

EDIT:

I attempted to put all files at the top level of the zip, but this still did not allow the zip to be loaded in Chrome

Interested in `exude` ?

exude

Execute the OS specific command.

Lately I noticed you are into cross OS commands, I think exude will be useful, if yes I am happy to help!

Broken on Windows unless you have .NET 4.5+ and PowerShell 3.0 installed

I had .NET 4.6 installed as well as PowerShell. However, I got the following error:

Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found.

I found lots of posts saying you need .NET 4.5 or greater -- not helpful -- and some dusty old forum post saying you need PowerShell 3. I installed that and now it works.


BTW the difference between Windows and Unix here is pretty funny.

Linux and Mac:

  • zip -r swag.zip folder

Windows:

  • Install .NET Framework 4.5 from some 100MB download
  • Install Powershell 3.0 as part of "Windows Management Framework 3.0" from 2012
  • powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('folder', 'wtf.zip'); }"
  • ... or you can do it all out of the box, but only by manual point and click. Ridiculous

[security] missing escaping for shell filenames

Can cause remote code execution if there is a code path to an attacker-supplied filename.

POC (Windows): put ' in filename.

POC (Other): put space or & or | in filename.

Since this library is the access point for shell execution, it's this library's responsibility to mangle file paths for the shell, not the caller's responsibility.

Specify encoding on win32 platform

  • For some reason, the default charset encoding of my system is not utf-8, and other people couldn't unzip the file generated on my computer. So I suggest specify the encoding to utf-8 explicitly.
function getZipCommand (inPath, outPath) {
  if (process.platform === 'win32') {
    return `powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; Add-Type -A 'System.Text.Encoding'; [IO.Compression.ZipFile]::CreateFromDirectory('${inPath}', '${outPath}', '${1}', '${true}', [System.Text.Encoding]::UTF8 ); }"`
  } else {
    var dirPath = path.dirname(inPath)
    var fileName = path.basename(inPath)
    return `cd ${JSON.stringify(dirPath)} && zip -r -y ${JSON.stringify(outPath)} ${JSON.stringify(fileName)}`
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.