Skip to content

Commit 209f45b

Browse files
committed
fix missing Buffer.isEncoding on Node 0.8
1 parent 9de15dc commit 209f45b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@
2121

2222
var Buffer = require('buffer').Buffer;
2323

24+
var isBufferEncoding = Buffer.isEncoding
25+
|| function(encoding) {
26+
switch (encoding && encoding.toLowerCase()) {
27+
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;
28+
default: return false;
29+
}
30+
}
31+
32+
2433
function assertEncoding(encoding) {
25-
if (encoding && !Buffer.isEncoding(encoding)) {
34+
if (encoding && !isBufferEncoding(encoding)) {
2635
throw new Error('Unknown encoding: ' + encoding);
2736
}
2837
}

0 commit comments

Comments
 (0)