Skip to content

Commit

Permalink
Fix Buffer.alloc bug #234
Browse files Browse the repository at this point in the history
A previous pull request was not compatible with Node 4.x
  • Loading branch information
keyesdav authored Jun 22, 2018
1 parent 80d259f commit ca2afb5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion zipFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ module.exports = function (/*String|Buffer*/input, /*Number*/inputType) {
entry.header.offset = dindex;
// data header
var dataHeader = entry.header.dataHeaderToBinary();
var postHeader = Buffer.alloc(name);
var postHeader;
try {
postHeader = Buffer.alloc(name.length, name); // using alloc will work on node 5.x+
} catch(e){
postHeader = new Buffer(name); // use deprecated method if alloc fails...
}
var dataLength = dataHeader.length + postHeader.length + compressedData.length;

dindex += dataLength;
Expand Down

0 comments on commit ca2afb5

Please sign in to comment.