Skip to content

Commit 8ee792f

Browse files
committed
version bump 1.0.8: Buffer.from node 4.x fix
1 parent c88a981 commit 8ee792f

File tree

12 files changed

+40
-24
lines changed

12 files changed

+40
-24
lines changed

bits/05_buf.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && process.versions.node);
22

3+
var Buffer_from = /*::(*/function(){}/*:: :any)*/;
4+
35
if(typeof Buffer !== 'undefined') {
4-
// $FlowIgnore
5-
if(!Buffer.from) Buffer.from = function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); };
6+
var nbfs = !Buffer.from;
7+
if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; }
8+
Buffer_from = nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer);
69
// $FlowIgnore
710
if(!Buffer.alloc) Buffer.alloc = function(n) { return new Buffer(n); };
811
}
@@ -15,7 +18,7 @@ function new_raw_buf(len/*:number*/) {
1518

1619
var s2a = function s2a(s/*:string*/) {
1720
if(has_buf) return Buffer.from(s, "binary");
18-
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
21+
return s.split("").map(function(x/*:string*/)/*:number*/{ return x.charCodeAt(0) & 0xff; });
1922
};
2023

2124
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;

bits/08_blob.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ if(has_buf/*:: && typeof Buffer !== 'undefined'*/) {
2222
};
2323
__hexlify = function(b/*:RawBytes|CFBlob*/,s/*:number*/,l/*:number*/)/*:string*/ { return Buffer.isBuffer(b)/*:: && b instanceof Buffer*/ ? b.toString('hex',s,s+l) : ___hexlify(b,s,l); };
2424
__toBuffer = function(bufs/*:Array<Array<RawBytes>>*/)/*:RawBytes*/ { return (bufs[0].length > 0 && Buffer.isBuffer(bufs[0][0])) ? Buffer.concat((bufs[0]/*:any*/)) : ___toBuffer(bufs);};
25-
s2a = function(s/*:string*/)/*:RawBytes*/ { return Buffer.from(s, "binary"); };
25+
// $FlowIgnore
26+
s2a = function(s/*:string*/)/*:RawBytes*/ { return Buffer_from(s, "binary"); };
2627
bconcat = function(bufs/*:Array<RawBytes>*/)/*:RawBytes*/ { return Buffer.isBuffer(bufs[0]) ? Buffer.concat(/*::(*/bufs/*:: :any)*/) : __bconcat(bufs); };
2728
}
2829

bits/31_version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exports.version = '1.0.7';
1+
exports.version = '1.0.8';

cfb.flow.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ var Base64 = (function make_b64(){
5050
})();
5151
var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && process.versions.node);
5252

53+
var Buffer_from = /*::(*/function(){}/*:: :any)*/;
54+
5355
if(typeof Buffer !== 'undefined') {
54-
// $FlowIgnore
55-
if(!Buffer.from) Buffer.from = function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); };
56+
var nbfs = !Buffer.from;
57+
if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; }
58+
Buffer_from = nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer);
5659
// $FlowIgnore
5760
if(!Buffer.alloc) Buffer.alloc = function(n) { return new Buffer(n); };
5861
}
@@ -65,7 +68,7 @@ function new_raw_buf(len/*:number*/) {
6568

6669
var s2a = function s2a(s/*:string*/) {
6770
if(has_buf) return Buffer.from(s, "binary");
68-
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
71+
return s.split("").map(function(x/*:string*/)/*:number*/{ return x.charCodeAt(0) & 0xff; });
6972
};
7073

7174
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
@@ -93,7 +96,8 @@ if(has_buf/*:: && typeof Buffer !== 'undefined'*/) {
9396
};
9497
__hexlify = function(b/*:RawBytes|CFBlob*/,s/*:number*/,l/*:number*/)/*:string*/ { return Buffer.isBuffer(b)/*:: && b instanceof Buffer*/ ? b.toString('hex',s,s+l) : ___hexlify(b,s,l); };
9598
__toBuffer = function(bufs/*:Array<Array<RawBytes>>*/)/*:RawBytes*/ { return (bufs[0].length > 0 && Buffer.isBuffer(bufs[0][0])) ? Buffer.concat((bufs[0]/*:any*/)) : ___toBuffer(bufs);};
96-
s2a = function(s/*:string*/)/*:RawBytes*/ { return Buffer.from(s, "binary"); };
99+
// $FlowIgnore
100+
s2a = function(s/*:string*/)/*:RawBytes*/ { return Buffer_from(s, "binary"); };
97101
bconcat = function(bufs/*:Array<RawBytes>*/)/*:RawBytes*/ { return Buffer.isBuffer(bufs[0]) ? Buffer.concat(/*::(*/bufs/*:: :any)*/) : __bconcat(bufs); };
98102
}
99103

@@ -183,7 +187,7 @@ type CFBFiles = {[n:string]:CFBEntry};
183187
/* [MS-CFB] v20171201 */
184188
var CFB = (function _CFB(){
185189
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
186-
exports.version = '1.0.7';
190+
exports.version = '1.0.8';
187191
/* [MS-CFB] 2.6.4 */
188192
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
189193
var L = l.split("/"), R = r.split("/");

cfb.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ var Base64 = (function make_b64(){
5050
})();
5151
var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && process.versions.node);
5252

53+
var Buffer_from = function(){};
54+
5355
if(typeof Buffer !== 'undefined') {
54-
// $FlowIgnore
55-
if(!Buffer.from) Buffer.from = function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); };
56+
var nbfs = !Buffer.from;
57+
if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; }
58+
Buffer_from = nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer);
5659
// $FlowIgnore
5760
if(!Buffer.alloc) Buffer.alloc = function(n) { return new Buffer(n); };
5861
}
@@ -93,7 +96,8 @@ if(has_buf) {
9396
};
9497
__hexlify = function(b,s,l) { return Buffer.isBuffer(b) ? b.toString('hex',s,s+l) : ___hexlify(b,s,l); };
9598
__toBuffer = function(bufs) { return (bufs[0].length > 0 && Buffer.isBuffer(bufs[0][0])) ? Buffer.concat((bufs[0])) : ___toBuffer(bufs);};
96-
s2a = function(s) { return Buffer.from(s, "binary"); };
99+
// $FlowIgnore
100+
s2a = function(s) { return Buffer_from(s, "binary"); };
97101
bconcat = function(bufs) { return Buffer.isBuffer(bufs[0]) ? Buffer.concat(bufs) : __bconcat(bufs); };
98102
}
99103

@@ -165,7 +169,7 @@ function new_buf(sz) {
165169
/* [MS-CFB] v20171201 */
166170
var CFB = (function _CFB(){
167171
var exports = {};
168-
exports.version = '1.0.7';
172+
exports.version = '1.0.8';
169173
/* [MS-CFB] 2.6.4 */
170174
function namecmp(l, r) {
171175
var L = l.split("/"), R = r.split("/");

dist/cfb.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ var Base64 = (function make_b64(){
5050
})();
5151
var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && process.versions.node);
5252

53+
var Buffer_from = function(){};
54+
5355
if(typeof Buffer !== 'undefined') {
54-
// $FlowIgnore
55-
if(!Buffer.from) Buffer.from = function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); };
56+
var nbfs = !Buffer.from;
57+
if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; }
58+
Buffer_from = nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer);
5659
// $FlowIgnore
5760
if(!Buffer.alloc) Buffer.alloc = function(n) { return new Buffer(n); };
5861
}
@@ -93,7 +96,8 @@ if(has_buf) {
9396
};
9497
__hexlify = function(b,s,l) { return Buffer.isBuffer(b) ? b.toString('hex',s,s+l) : ___hexlify(b,s,l); };
9598
__toBuffer = function(bufs) { return (bufs[0].length > 0 && Buffer.isBuffer(bufs[0][0])) ? Buffer.concat((bufs[0])) : ___toBuffer(bufs);};
96-
s2a = function(s) { return Buffer.from(s, "binary"); };
99+
// $FlowIgnore
100+
s2a = function(s) { return Buffer_from(s, "binary"); };
97101
bconcat = function(bufs) { return Buffer.isBuffer(bufs[0]) ? Buffer.concat(bufs) : __bconcat(bufs); };
98102
}
99103

@@ -165,7 +169,7 @@ function new_buf(sz) {
165169
/* [MS-CFB] v20171201 */
166170
var CFB = (function _CFB(){
167171
var exports = {};
168-
exports.version = '1.0.7';
172+
exports.version = '1.0.8';
169173
/* [MS-CFB] 2.6.4 */
170174
function namecmp(l, r) {
171175
var L = l.split("/"), R = r.split("/");

dist/cfb.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cfb.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xlscfb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type CFBFiles = {[n:string]:CFBEntry};
3838
/* [MS-CFB] v20171201 */
3939
var CFB = (function _CFB(){
4040
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
41-
exports.version = '1.0.7';
41+
exports.version = '1.0.8';
4242
/* [MS-CFB] 2.6.4 */
4343
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
4444
var L = l.split("/"), R = r.split("/");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cfb",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"author": "sheetjs",
55
"description": "Compound File Binary File Format extractor",
66
"keywords": [

0 commit comments

Comments
 (0)