@@ -51,14 +51,14 @@ function typedArraySupport () {
51
51
}
52
52
}
53
53
54
- function createBuffer ( that , length ) {
54
+ function createBuffer ( length ) {
55
55
if ( K_MAX_LENGTH < length ) {
56
56
throw new RangeError ( 'Invalid typed array length' )
57
57
}
58
58
// Return an augmented `Uint8Array` instance
59
- that = new Uint8Array ( length )
60
- that . __proto__ = Buffer . prototype
61
- return that
59
+ var buf = new Uint8Array ( length )
60
+ buf . __proto__ = Buffer . prototype
61
+ return buf
62
62
}
63
63
64
64
/**
@@ -79,9 +79,9 @@ function Buffer (arg, encodingOrOffset, length) {
79
79
'If encoding is specified then the first argument must be a string'
80
80
)
81
81
}
82
- return allocUnsafe ( this , arg )
82
+ return allocUnsafe ( arg )
83
83
}
84
- return from ( this , arg , encodingOrOffset , length )
84
+ return from ( arg , encodingOrOffset , length )
85
85
}
86
86
87
87
Buffer . prototype . __proto__ = Uint8Array . prototype
@@ -100,20 +100,20 @@ if (typeof Symbol !== 'undefined' && Symbol.species &&
100
100
101
101
Buffer . poolSize = 8192 // not used by this implementation
102
102
103
- function from ( that , value , encodingOrOffset , length ) {
103
+ function from ( value , encodingOrOffset , length ) {
104
104
if ( typeof value === 'number' ) {
105
105
throw new TypeError ( '"value" argument must not be a number' )
106
106
}
107
107
108
108
if ( typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer ) {
109
- return fromArrayBuffer ( that , value , encodingOrOffset , length )
109
+ return fromArrayBuffer ( value , encodingOrOffset , length )
110
110
}
111
111
112
112
if ( typeof value === 'string' ) {
113
- return fromString ( that , value , encodingOrOffset )
113
+ return fromString ( value , encodingOrOffset )
114
114
}
115
115
116
- return fromObject ( that , value )
116
+ return fromObject ( value )
117
117
}
118
118
119
119
/**
@@ -125,7 +125,7 @@ function from (that, value, encodingOrOffset, length) {
125
125
* Buffer.from(arrayBuffer[, byteOffset[, length]])
126
126
**/
127
127
Buffer . from = function ( value , encodingOrOffset , length ) {
128
- return from ( null , value , encodingOrOffset , length )
128
+ return from ( value , encodingOrOffset , length )
129
129
}
130
130
131
131
function assertSize ( size ) {
@@ -136,49 +136,49 @@ function assertSize (size) {
136
136
}
137
137
}
138
138
139
- function alloc ( that , size , fill , encoding ) {
139
+ function alloc ( size , fill , encoding ) {
140
140
assertSize ( size )
141
141
if ( size <= 0 ) {
142
- return createBuffer ( that , size )
142
+ return createBuffer ( size )
143
143
}
144
144
if ( fill !== undefined ) {
145
145
// Only pay attention to encoding if it's a string. This
146
146
// prevents accidentally sending in a number that would
147
147
// be interpretted as a start offset.
148
148
return typeof encoding === 'string'
149
- ? createBuffer ( that , size ) . fill ( fill , encoding )
150
- : createBuffer ( that , size ) . fill ( fill )
149
+ ? createBuffer ( size ) . fill ( fill , encoding )
150
+ : createBuffer ( size ) . fill ( fill )
151
151
}
152
- return createBuffer ( that , size )
152
+ return createBuffer ( size )
153
153
}
154
154
155
155
/**
156
156
* Creates a new filled Buffer instance.
157
157
* alloc(size[, fill[, encoding]])
158
158
**/
159
159
Buffer . alloc = function ( size , fill , encoding ) {
160
- return alloc ( null , size , fill , encoding )
160
+ return alloc ( size , fill , encoding )
161
161
}
162
162
163
- function allocUnsafe ( that , size ) {
163
+ function allocUnsafe ( size ) {
164
164
assertSize ( size )
165
- return createBuffer ( that , size < 0 ? 0 : checked ( size ) | 0 )
165
+ return createBuffer ( size < 0 ? 0 : checked ( size ) | 0 )
166
166
}
167
167
168
168
/**
169
169
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
170
170
* */
171
171
Buffer . allocUnsafe = function ( size ) {
172
- return allocUnsafe ( null , size )
172
+ return allocUnsafe ( size )
173
173
}
174
174
/**
175
175
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
176
176
*/
177
177
Buffer . allocUnsafeSlow = function ( size ) {
178
- return allocUnsafe ( null , size )
178
+ return allocUnsafe ( size )
179
179
}
180
180
181
- function fromString ( that , string , encoding ) {
181
+ function fromString ( string , encoding ) {
182
182
if ( typeof encoding !== 'string' || encoding === '' ) {
183
183
encoding = 'utf8'
184
184
}
@@ -188,30 +188,30 @@ function fromString (that, string, encoding) {
188
188
}
189
189
190
190
var length = byteLength ( string , encoding ) | 0
191
- that = createBuffer ( that , length )
191
+ var buf = createBuffer ( length )
192
192
193
- var actual = that . write ( string , encoding )
193
+ var actual = buf . write ( string , encoding )
194
194
195
195
if ( actual !== length ) {
196
196
// Writing a hex string, for example, that contains invalid characters will
197
197
// cause everything after the first invalid character to be ignored. (e.g.
198
198
// 'abxxcd' will be treated as 'ab')
199
- that = that . slice ( 0 , actual )
199
+ buf = buf . slice ( 0 , actual )
200
200
}
201
201
202
- return that
202
+ return buf
203
203
}
204
204
205
- function fromArrayLike ( that , array ) {
205
+ function fromArrayLike ( array ) {
206
206
var length = array . length < 0 ? 0 : checked ( array . length ) | 0
207
- that = createBuffer ( that , length )
207
+ var buf = createBuffer ( length )
208
208
for ( var i = 0 ; i < length ; i += 1 ) {
209
- that [ i ] = array [ i ] & 255
209
+ buf [ i ] = array [ i ] & 255
210
210
}
211
- return that
211
+ return buf
212
212
}
213
213
214
- function fromArrayBuffer ( that , array , byteOffset , length ) {
214
+ function fromArrayBuffer ( array , byteOffset , length ) {
215
215
array . byteLength // this throws if `array` is not a valid ArrayBuffer
216
216
217
217
if ( byteOffset < 0 || array . byteLength < byteOffset ) {
@@ -222,44 +222,44 @@ function fromArrayBuffer (that, array, byteOffset, length) {
222
222
throw new RangeError ( '\'length\' is out of bounds' )
223
223
}
224
224
225
+ var buf
225
226
if ( byteOffset === undefined && length === undefined ) {
226
- array = new Uint8Array ( array )
227
+ buf = new Uint8Array ( array )
227
228
} else if ( length === undefined ) {
228
- array = new Uint8Array ( array , byteOffset )
229
+ buf = new Uint8Array ( array , byteOffset )
229
230
} else {
230
- array = new Uint8Array ( array , byteOffset , length )
231
+ buf = new Uint8Array ( array , byteOffset , length )
231
232
}
232
233
233
- // Return an augmented `Uint8Array` instance, for best performance
234
- that = array
235
- that . __proto__ = Buffer . prototype
236
- return that
234
+ // Return an augmented `Uint8Array` instance
235
+ buf . __proto__ = Buffer . prototype
236
+ return buf
237
237
}
238
238
239
- function fromObject ( that , obj ) {
239
+ function fromObject ( obj ) {
240
240
if ( Buffer . isBuffer ( obj ) ) {
241
241
var len = checked ( obj . length ) | 0
242
- that = createBuffer ( that , len )
242
+ var buf = createBuffer ( len )
243
243
244
- if ( that . length === 0 ) {
245
- return that
244
+ if ( buf . length === 0 ) {
245
+ return buf
246
246
}
247
247
248
- obj . copy ( that , 0 , 0 , len )
249
- return that
248
+ obj . copy ( buf , 0 , 0 , len )
249
+ return buf
250
250
}
251
251
252
252
if ( obj ) {
253
253
if ( ( typeof ArrayBuffer !== 'undefined' &&
254
254
obj . buffer instanceof ArrayBuffer ) || 'length' in obj ) {
255
255
if ( typeof obj . length !== 'number' || isnan ( obj . length ) ) {
256
- return createBuffer ( that , 0 )
256
+ return createBuffer ( 0 )
257
257
}
258
- return fromArrayLike ( that , obj )
258
+ return fromArrayLike ( obj )
259
259
}
260
260
261
261
if ( obj . type === 'Buffer' && Array . isArray ( obj . data ) ) {
262
- return fromArrayLike ( that , obj . data )
262
+ return fromArrayLike ( obj . data )
263
263
}
264
264
}
265
265
@@ -1030,6 +1030,7 @@ Buffer.prototype.slice = function slice (start, end) {
1030
1030
if ( end < start ) end = start
1031
1031
1032
1032
var newBuf = this . subarray ( start , end )
1033
+ // Return an augmented `Uint8Array` instance
1033
1034
newBuf . __proto__ = Buffer . prototype
1034
1035
return newBuf
1035
1036
}
0 commit comments