kriskowal / zip

An implementation of unzip in JavaScript for Node
MIT License
85 stars 28 forks source link

Added getMode method to determine the chmod on unix systems #10

Closed steffenmllr closed 11 years ago

steffenmllr commented 11 years ago

hey there,

I needed to access the chmod value from the central directory file header in order to get a mac app to unpack so I added a getMode to the Entry and the mode to the Entry constructor.

My sample file was https://s3.amazonaws.com/node-webkit/v0.6.3/node-webkit-v0.6.3-osx-ia32.zip

Here is the sample code to unpack:

var ZIP = require('zip');
var fs = require('fs-extra');
var data = fs.readFileSync('node-webkit-v0.6.3-osx-ia32.zip');
var reader = ZIP.Reader(data);
reader.forEach(function (entry) {
    var mode = entry.getMode(),
        fileName = entry.getName();
    if(entry.isDirectory()) {
        fs.mkdirs(fileName, function(err){
            if(mode) fs.chmodSync(fileName, mode);
        });
    } else {
        fs.writeFileSync(fileName, entry.getData());
        if(mode) fs.chmodSync(fileName, mode);
    }
});
kriskowal commented 11 years ago

@steffenmllr, I’ve added you as a collaborator so you can merge this yourself. I wish I had the time to review it properly myself. Just let me know when I can publish a new release. I would appreciate it if you would wrangle the release notes and let me know whether it’s appropriate to do a major, minor, or patch release. If you send me your NPM user name, I might delegate that to you as well.

steffenmllr commented 11 years ago

@kriskowal my npm name is steffen - I'll push the release notes this week

kriskowal commented 11 years ago

@steffenmllr I’ve granted you the right to use npm publish on this project. I like to use npm version <patch|minor|major> to update package.json and add the version tag. I then push both master and the tag back up here. Make sure the verify the specs, and the release notes go in CHANGES.md.

Thanks! I’ll monitor.

As for long term vision, I hope to work with @stuk to bring this project together with https://github.com/Stuk/jszip, but it is not a priority.