forked from nodejs/string_decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.js
More file actions
80 lines (71 loc) · 2.52 KB
/
Copy pathfiles.js
File metadata and controls
80 lines (71 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* This file lists the files to be fetched from the node repo
* in the /lib/ directory which will be placed in the ../lib/
* directory after having each of the "replacements" in the
* array for that file applied to it. The replacements are
* simply the arguments to String#replace, so they can be
* strings, regexes, functions.
*/
module.exports['string_decoder.js'] = [
// we do not need internal/util anymore
[
/const internalUtil = require\('internal\/util'\);/
, ''
]
, [
/(?:var|const) (?:{ )Buffer(?: }) = require\('buffer'\)(?:\.Buffer)?;/,
`/*<replacement>*/
var Buffer = require('safe-buffer').Buffer;
/*</replacement>*/
`
]
// add Buffer.isEncoding where missing
, [
/const isEncoding = Buffer\[internalUtil.kIsEncodingSymbol\];/
, '\nvar isEncoding = Buffer.isEncoding'
+ '\n || function(encoding) {'
+ '\n encoding = \'\' + encoding'
+ '\n switch (encoding && encoding.toLowerCase()) {'
+ '\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;'
+ '\n default: return false;'
+ '\n }'
+ '\n }'
+ '\n'
+ '\nfunction _normalizeEncoding(enc) {'
+ '\n if (!enc) return \'utf8\';'
+ '\n var retried;'
+ '\n while (true) {'
+ '\n switch (enc) {'
+ '\n case \'utf8\':'
+ '\n case \'utf-8\':'
+ '\n return \'utf8\';'
+ '\n case \'ucs2\':'
+ '\n case \'ucs-2\':'
+ '\n case \'utf16le\':'
+ '\n case \'utf-16le\':'
+ '\n return \'utf16le\';'
+ '\n case \'latin1\':'
+ '\n case \'binary\':'
+ '\n return \'latin1\';'
+ '\n case \'base64\':'
+ '\n case \'ascii\':'
+ '\n case \'hex\':'
+ '\n return enc;'
+ '\n default:'
+ '\n if (retried) return; // undefined'
+ '\n enc = (\'\' + enc).toLowerCase();'
+ '\n retried = true;'
+ '\n }'
+ '\n }'
+ '\n };'
]
// use custom Buffer.isEncoding reference
, [
/Buffer\.isEncoding\(/g
, 'isEncoding\('
]
// use _normalizeEncoding everywhere
, [
/internalUtil\.normalizeEncoding/g
, '_normalizeEncoding'
]
]