8000 missing Buffer.isEncoding() on Node 0.8 · rvagg/archived-string_decoder@03eca8a · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 5, 2018. It is now read-only.

Commit 03eca8a

Browse files
committed
missing Buffer.isEncoding() on Node 0.8
1 parent 209f45b commit 03eca8a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

build/files.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,26 @@
99
module.exports['string_decoder.js'] = [
1010

1111
// pull in Bufer as a require
12+
// add Buffer.isEncoding where missing
1213
[
1314
/^(\/\/ USE OR OTHER DEALINGS IN THE SOFTWARE\.)/m
14-
, '$1\n\nvar Buffer = require(\'buffer\').Buffer;'
15+
, '$1\n\nvar Buffer = require(\'buffer\').Buffer;'
16+
+ '\n'
17+
+ '\nvar isBufferEncoding = Buffer.isEncoding'
18+
+ '\n || function(encoding) {'
19+
+ '\n switch (encoding && encoding.toLowerCase()) {'
20+
+ '\n case \'hex\': case \'utf8\': case \'utf-8\': case \'ascii\': case \'binary\': case \'base64\': case \'ucs2\': case \'ucs-2\': case \'utf16le\': case \'utf-16le\': case \'raw\': return true;'
21+
+ '\n default: return false;'
22+
+ '\n }'
23+
+ '\n }'
24+
+ '\n'
25+
26+
]
27+
28+
// use custom Buffer.isEncoding reference
29+
, [
30+
/Buffer\.isEncoding\(/g
31+
, 'isBufferEncoding\('
1532
]
1633

1734
]

0 commit comments

Comments
 (0)
0