File tree 6 files changed +53
-6
lines changed
6 files changed +53
-6
lines changed Original file line number Diff line number Diff line change @@ -53,10 +53,20 @@ if (!StringDecoder.prototype.end) // Node v0.8 doesn't have this method.
53
53
54
54
55
55
function InternalDecoder ( options , codec ) {
56
- StringDecoder . call ( this , codec . enc ) ;
56
+ this . decoder = new StringDecoder ( codec . enc ) ;
57
57
}
58
58
59
- InternalDecoder . prototype = StringDecoder . prototype ;
59
+ InternalDecoder . prototype . write = function ( buf ) {
60
+ if ( ! Buffer . isBuffer ( buf ) ) {
61
+ buf = Buffer . from ( buf ) ;
62
+ }
63
+
64
+ return this . decoder . write ( buf ) ;
65
+ }
66
+
67
+ InternalDecoder . prototype . end = function ( ) {
68
+ return this . decoder . end ( ) ;
69
+ }
60
70
61
71
62
72
//------------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -112,6 +112,11 @@ function Utf16Decoder(options, codec) {
112
112
113
113
Utf16Decoder . prototype . write = function ( buf ) {
114
114
if ( ! this . decoder ) {
115
+ // Support Uint8Array
116
+ if ( ! Buffer . isBuffer ( buf ) ) {
117
+ buf = Buffer . from ( buf )
118
+ }
119
+
115
120
// Codec is not chosen yet. Accumulate initial bytes.
116
121
this . initialBytes . push ( buf ) ;
117
122
this . initialBytesLen += buf . length ;
Original file line number Diff line number Diff line change @@ -107,6 +107,11 @@ Utf32Decoder.prototype.write = function(src) {
107
107
if ( src . length === 0 )
108
108
return '' ;
109
109
110
+ // Support Uint8Array
111
+ if ( ! Buffer . isBuffer ( src ) ) {
112
+ src = Buffer . from ( src ) ;
113
+ }
114
+
110
115
if ( this . overflow )
111
116
src = Buffer . concat ( [ this . overflow , src ] ) ;
112
117
@@ -203,7 +208,12 @@ function Utf32AutoDecoder(options, codec) {
203
208
}
204
209
205
210
Utf32AutoDecoder . prototype . write = function ( buf ) {
206
- if ( ! this . decoder ) {
211
+ if ( ! this . decoder ) {
212
+ // Support Uint8Array
213
+ if ( ! Buffer . isBuffer ( buf ) ) {
214
+ buf = Buffer . from ( buf ) ;
215
+ }
216
+
207
217
// Codec is not chosen yet. Accumulate initial bytes.
208
218
this . initialBytes . push ( buf ) ;
209
219
this . initialBytesLen += buf . length ;
Original file line number Diff line number Diff line change @@ -36,6 +36,27 @@ describe("iconv-lite", function() {
36
36
var str = iconv . decode ( buf , "utf8" ) ;
37
37
assert . equal ( str , "💩" ) ;
38
38
} ) ;
39
+
40
+ it ( "supports passing Uint8Array to decode for all encodings" , function ( ) {
41
+ iconv . encode ( '' , 'utf8' ) ; // Load all encodings.
42
+
43
+ var encodings = Object . keys ( iconv . encodings )
44
+ encodings
45
+ . filter ( encoding =>
46
+ ! encoding . startsWith ( '_' )
47
+ // https://github.com/ashtuchkin/iconv-lite/issues/231
48
+ && encoding !== 'base64' && encoding !== 'hex'
49
+ )
50
+ . forEach ( function ( encoding ) {
51
+ var expected = 'Lorem ipsum' ;
52
+
53
+ var encoded = iconv . encode ( expected , encoding ) ;
54
+ var uint8Array = Uint8Array . from ( encoded ) ;
55
+
56
+ var actual = iconv . decode ( uint8Array , encoding ) ;
57
+ assert . equal ( actual , expected , encoding ) ;
58
+ } )
59
+ } ) ;
39
60
} ) ;
40
61
41
62
describe ( "stream module" , function ( ) {
Original file line number Diff line number Diff line change 1
1
// Karma configuration
2
2
// Generated on Sat May 23 2020 18:02:48 GMT-0400 (Eastern Daylight Time)
3
+ process . env . CHROME_BIN = require ( 'puppeteer' ) . executablePath ( )
3
4
4
5
module . exports = function ( config ) {
5
6
config . set ( {
@@ -64,7 +65,7 @@ module.exports = function(config) {
64
65
65
66
// start these browsers
66
67
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
67
- browsers : [ 'PhantomJS ' ] ,
68
+ browsers : [ 'ChromeHeadless ' ] ,
68
69
69
70
70
71
// Continuous Integration mode
Original file line number Diff line number Diff line change 7
7
},
8
8
"devDependencies" : {
9
9
"karma" : " ^5.0.9" ,
10
+ "karma-chrome-launcher" : " ^3.1.0" ,
10
11
"karma-mocha" : " ^2.0.1" ,
11
- "karma-phantomjs-launcher" : " ^1.0.4" ,
12
12
"karma-webpack" : " ^4.0.2" ,
13
13
"mocha" : " ^7.2.0" ,
14
- "phantomjs-prebuilt " : " ^2.1.16 " ,
14
+ "puppeteer " : " ^4.0.0 " ,
15
15
"webpack" : " ^4.43.0"
16
16
},
17
17
"dependencies" : {
You can’t perform that action at this time.
0 commit comments