File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -459,6 +459,11 @@ multiple worker threads.
459459### ` new buffer.Blob([sources[, options]]) `
460460<!-- YAML
461461added: v15.7.0
462+ changes:
463+ - version: REPLACEME
464+ pr-url: https://github.com/nodejs/node/pull/39708
465+ description: Added the standard `endings` option to replace line-endings,
466+ and removed the non-standard `encoding` option.
462467-->
463468
464469* ` sources ` {string[ ] |ArrayBuffer[ ] |TypedArray[ ] |DataView[ ] |Blob[ ] } An array
@@ -477,9 +482,9 @@ Creates a new `Blob` object containing a concatenation of the given sources.
477482{ArrayBuffer}, {TypedArray}, {DataView}, and {Buffer} sources are copied into
478483the 'Blob' and can therefore be safely modified after the 'Blob' is created.
479484
480- String sources are encoded as UTF-8 byte sequences and copied into the blob .
485+ String sources are encoded as UTF-8 byte sequences and copied into the Blob .
481486Unmatched surrogate pairs within each string part will be replaced by Unicode
482- 0xFFFD replacement characters.
487+ U+FFFD replacement characters.
483488
484489### ` blob.arrayBuffer() `
485490<!-- YAML
Original file line number Diff line number Diff line change 99 PromiseReject,
1010 SafePromisePrototypeFinally,
1111 ReflectConstruct,
12+ RegExpPrototypeSymbolReplace,
1213 RegExpPrototypeTest,
1314 StringPrototypeToLowerCase,
1415 StringPrototypeSplit,
@@ -111,7 +112,7 @@ function getSource(source, endings) {
111112 } else if ( ! isArrayBufferView ( source ) ) {
112113 source = `${ source } ` ;
113114 if ( endings === 'native' )
114- source = source . replaceAll ( / ( \n | \r \n ) / g , lazyEOL ( ) ) ;
115+ source = RegExpPrototypeSymbolReplace ( / \n | \r \n / g , source , lazyEOL ( ) ) ;
115116 source = enc . encode ( source ) ;
116117 }
117118
@@ -131,7 +132,7 @@ class Blob {
131132 * @param {{
132133 * endings? : string,
133134 * type? : string,
134- * }} options
135+ * }} [ options]
135136 * @returns
136137 */
137138 constructor ( sources = [ ] , options = { } ) {
@@ -148,7 +149,7 @@ class Blob {
148149 } = options ;
149150
150151 endings = `${ endings } ` ;
151- if ( endings !== 'transparent' || endings !== 'native' )
152+ if ( endings !== 'transparent' && endings !== 'native' )
152153 throw new ERR_INVALID_ARG_VALUE ( 'options.endings' , endings ) ;
153154
154155 let length = 0 ;
Original file line number Diff line number Diff line change 1+ // Flags: --no-warnings
12'use strict' ;
23
34const common = require ( '../common' ) ;
45const assert = require ( 'assert' ) ;
56const { Blob } = require ( 'buffer' ) ;
67const { inspect } = require ( 'util' ) ;
8+ const { EOL } = require ( 'os' ) ;
79
810{
911 const b = new Blob ( ) ;
@@ -210,7 +212,7 @@ assert.throws(() => new Blob({}), {
210212
211213{
212214 const b = new Blob ( [ 'hello\n' ] , { endings : 'native' } ) ;
213- assert . strictEqual ( b . size , 7 ) ;
215+ assert . strictEqual ( b . size , EOL . length + 5 ) ;
214216
215217 [ 1 , { } , 'foo' ] . forEach ( ( endings ) => {
216218 assert . throws ( ( ) => new Blob ( [ ] , { endings } ) , {
You can’t perform that action at this time.
0 commit comments