Comparing version
@@ -0,2 +1,6 @@ | ||
# 1.1.1 | ||
- Added ``getMode`` function to be able to | ||
use fs.chmod on darwin and linux | ||
# 0.0.4 | ||
@@ -3,0 +7,0 @@ |
{ | ||
"name": "zip", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "An implementation of unzip for JavaScript", | ||
@@ -30,3 +30,6 @@ "keywords": [ | ||
"url": "git://github.com/kriskowal/zip.git" | ||
}, | ||
"scripts": { | ||
"test": "node test" | ||
} | ||
} |
15
test.js
var ZIP = require("./zip"); | ||
var FS = require("fs"); | ||
var assert = require("assert"); | ||
@@ -9,6 +10,7 @@ console.log("-------------------"); | ||
var reader = ZIP.Reader(data); | ||
console.log(reader.toObject('utf-8')); | ||
var readFromBuffer = reader.toObject('utf-8'); | ||
console.log(readFromBuffer); | ||
reader.forEach(function (entry) { | ||
console.log(entry.getName(), entry.lastModified()); | ||
console.log(entry.getName(), entry.lastModified(), entry.getMode()); | ||
}); | ||
@@ -20,5 +22,6 @@ | ||
FS.open("zip.zip", "r", "0666", function(err, fd) { | ||
var reader = ZIP.Reader(fd); | ||
console.log(reader.toObject('utf-8')); | ||
}); | ||
var reader = ZIP.Reader(fd); | ||
var readFromFileDescriptor = reader.toObject('utf-8'); | ||
console.log(readFromFileDescriptor); | ||
assert.deepEqual(readFromBuffer, readFromFileDescriptor, 'READ from Buffer MUST be equal to READ from file descriptor'); | ||
}); |
27
zip.js
@@ -11,2 +11,3 @@ // Tom Robinson | ||
var END_OF_CENTRAL_DIRECTORY_RECORD = 0x06054b50; | ||
var MADE_BY_UNIX = 3; // See http://www.pkware.com/documents/casestudies/APPNOTE.TXT | ||
@@ -193,3 +194,3 @@ var Reader = exports.Reader = function (data) { | ||
if (structure.signature !== CENTRAL_DIRECTORY_FILE_HEADER) | ||
throw new Error("ZIP central directory file header signature invalid (expects 0x04034b50, actually 0x" + structure.signature.toString(16) +")"); | ||
throw new Error("ZIP central directory file header signature invalid (expects 0x02014b50, actually 0x" + structure.signature.toString(16) +")"); | ||
@@ -220,2 +221,3 @@ structure.version = stream.readInteger(2); // Version made by | ||
structure.file_comment = stream.readString(k); // File comment | ||
structure.mode = stream.detectChmod(structure.version, structure.external_file_attributes); // chmod | ||
@@ -225,2 +227,14 @@ return structure; | ||
Reader.prototype.detectChmod = function(versionMadeBy, externalFileAttributes) { | ||
var madeBy = versionMadeBy >> 8, | ||
mode = externalFileAttributes >>> 16, | ||
chmod = false; | ||
mode = (mode & 0x1ff); | ||
if (madeBy === MADE_BY_UNIX && (process.platform === 'darwin' || process.platform === 'linux')) { | ||
chmod = mode.toString(8); | ||
} | ||
return chmod; | ||
} | ||
// finds the end of central directory record | ||
@@ -271,3 +285,3 @@ // I'd like to slap whoever thought it was a good idea to put a variable length comment field here | ||
if (structure.signature !== END_OF_CENTRAL_DIRECTORY_RECORD) | ||
throw new Error("ZIP end of central directory record signature invalid (expects 0x04034b50, actually 0x" + structure.signature.toString(16) +")"); | ||
throw new Error("ZIP end of central directory record signature invalid (expects 0x06054b50, actually 0x" + structure.signature.toString(16) +")"); | ||
@@ -336,3 +350,3 @@ structure.disk_number = stream.readInteger(2); // Number of this disk | ||
return new Entry(localHeader, stream, start, centralHeader.compressed_size, centralHeader.compression_method); | ||
return new Entry(localHeader, stream, start, centralHeader.compressed_size, centralHeader.compression_method, centralHeader.mode); | ||
} | ||
@@ -375,3 +389,4 @@ }; | ||
var Entry = exports.Entry = function (header, realStream, start, compressedSize, compressionMethod) { | ||
var Entry = exports.Entry = function (header, realStream, start, compressedSize, compressionMethod, mode) { | ||
this._mode = mode; | ||
this._header = header; | ||
@@ -411,2 +426,6 @@ this._realStream = realStream; | ||
Entry.prototype.getMode = function () { | ||
return this._mode; | ||
}; | ||
var bytesToNumberLE = function (bytes) { | ||
@@ -413,0 +432,0 @@ var acc = 0; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
45736
2.66%10
11.11%1111
1.74%1
Infinity%