| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8380800 commit dca8678
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -361,6 +361,11 @@ class Blob { | |||
| 361 | 361 | queueMicrotask(() => { | |
| 362 | 362 | if (c.desiredSize <= 0) { | |
| 363 | 363 | // A manual backpressure check. | |
| 364 | + if (this.pendingPulls.length !== 0) { | ||
| 365 | + // A case of waiting pull finished (= not yet canceled) | ||
| 366 | + const pending = this.pendingPulls.shift(); | ||
| 367 | + pending.resolve(); | ||
| 368 | + } | ||
| 364 | 369 | return; | |
| 365 | 370 | } | |
| 366 | 371 | readNext(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -269,6 +269,64 @@ assert.throws(() => new Blob({}), { | |||
| 269 | 269 | reader.closed.then(common.mustCall()); | |
| 270 | 270 | })().then(common.mustCall()); | |
| 271 | 271 | ||
| 272 | + (async () => { | ||
| 273 | + const b = new Blob(['A', 'B', 'C']); | ||
| 274 | + const stream = b.stream(); | ||
| 275 | + const chunks = []; | ||
| 276 | + const decoder = new TextDecoder(); | ||
| 277 | + await stream.pipeTo(new WritableStream({ | ||
| 278 | + write(chunk) { | ||
| 279 | + chunks.push(decoder.decode(chunk, { stream: true })); | ||
| 280 | + } | ||
| 281 | + })); | ||
| 282 | + assert.strictEqual(chunks.join(''), 'ABC'); | ||
| 283 | + })().then(common.mustCall()); | ||
| 284 | + | ||
| 285 | + (async () => { | ||
| 286 | + const b = new Blob(['A', 'B', 'C']); | ||
| 287 | + const stream = b.stream(); | ||
| 288 | + const chunks = []; | ||
| 289 | + const decoder = new TextDecoder(); | ||
| 290 | + await stream.pipeTo( | ||
| 291 | + new WritableStream({ | ||
| 292 | + write(chunk) { | ||
| 293 | + chunks.push(decoder.decode(chunk, { stream: true })); | ||
| 294 | + }, | ||
| 295 | + }) | ||
| 296 | + ); | ||
| 297 | + assert.strictEqual(chunks.join(''), 'ABC'); | ||
| 298 | + })().then(common.mustCall()); | ||
| 299 | + | ||
| 300 | + (async () => { | ||
| 301 | + // Ref: https://github.com/nodejs/node/issues/48668 | ||
| 302 | + const chunks = []; | ||
| 303 | + const stream = new Blob(['Hello world']).stream(); | ||
| 304 | + const decoder = new TextDecoder(); | ||
| 305 | + await Promise.resolve(); | ||
| 306 | + await stream.pipeTo( | ||
| 307 | + new WritableStream({ | ||
| 308 | + write(chunk) { | ||
| 309 | + chunks.push(decoder.decode(chunk, { stream: true })); | ||
| 310 | + }, | ||
| 311 | + }) | ||
| 312 | + ); | ||
| 313 | + assert.strictEqual(chunks.join(''), 'Hello world'); | ||
| 314 | + })().then(common.mustCall()); | ||
| 315 | + | ||
| 316 | + (async () => { | ||
| 317 | + // Ref: https://github.com/nodejs/node/issues/48668 | ||
| 318 | + if (common.hasCrypto) { | ||
| 319 | + // Can only do this test if we have node built with crypto | ||
| 320 | + const file = new Blob(['<svg></svg>'], { type: 'image/svg+xml' }); | ||
| 321 | + const url = URL.createObjectURL(file); | ||
| 322 | + const res = await fetch(url); | ||
| 323 | + const blob = await res.blob(); | ||
| 324 | + assert.strictEqual(blob.size, 11); | ||
| 325 | + assert.strictEqual(blob.type, 'image/svg+xml'); | ||
| 326 | + assert.strictEqual(await blob.text(), '<svg></svg>'); | ||
| 327 | + } | ||
| 328 | + })().then(common.mustCall()); | ||
| 329 | + | ||
| 272 | 330 | (async () => { | |
| 273 | 331 | const b = new Blob(Array(10).fill('hello')); | |
| 274 | 332 | const stream = b.stream(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments