|
1 |
| -// Flags: --no-warnings |
| 1 | +// Flags: --no-warnings --expose-internals |
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | const common = require('../common');
|
5 | 5 | const assert = require('assert');
|
6 | 6 | const { Blob } = require('buffer');
|
7 | 7 | const { inspect } = require('util');
|
8 | 8 | const { EOL } = require('os');
|
| 9 | +const { kState } = require('internal/webstreams/util'); |
9 | 10 |
|
10 | 11 | {
|
11 | 12 | const b = new Blob();
|
@@ -237,6 +238,50 @@ assert.throws(() => new Blob({}), {
|
237 | 238 | assert(res.done);
|
238 | 239 | })().then(common.mustCall());
|
239 | 240 |
|
| 241 | +(async () => { |
| 242 | + const b = new Blob(Array(10).fill('hello')); |
| 243 | + const reader = b.stream().getReader(); |
| 244 | + const chunks = []; |
| 245 | + while (true) { |
| 246 | + const res = await reader.read(); |
| 247 | + if (res.done) break; |
| 248 | + assert.strictEqual(res.value.byteLength, 5); |
| 249 | + chunks.push(res.value); |
| 250 | + } |
| 251 | + assert.strictEqual(chunks.length, 10); |
| 252 | +})().then(common.mustCall()); |
| 253 | + |
| 254 | +(async () => { |
| 255 | + const b = new Blob(Array(10).fill('hello')); |
| 256 | + const reader = b.stream().getReader(); |
| 257 | + const chunks = []; |
| 258 | + while (true) { |
| 259 | + const res = await reader.read(); |
| 260 | + if (chunks.length === 5) { |
| 261 | + reader.cancel('boom'); |
| 262 | + break; |
| 263 | + } |
| 264 | + if (res.done) break; |
| 265 | + assert.strictEqual(res.value.byteLength, 5); |
| 266 | + chunks.push(res.value); |
| 267 | + } |
| 268 | + assert.strictEqual(chunks.length, 5); |
| 269 | + reader.closed.then(common.mustCall()); |
| 270 | +})().then(common.mustCall()); |
| 271 | + |
| 272 | +(async () => { |
| 273 | + const b = new Blob(Array(10).fill('hello')); |
| 274 | + const stream = b.stream(); |
| 275 | + const reader = stream.getReader(); |
| 276 | + assert.strictEqual(stream[kState].controller.desiredSize, 1); |
| 277 | + const { value, done } = await reader.read(); |
| 278 | + assert.strictEqual(value.byteLength, 5); |
| 279 | + assert(!done); |
| 280 | + setTimeout(() => { |
| 281 | + assert.strictEqual(stream[kState].controller.desiredSize, 0); |
| 282 | + }, 0); |
| 283 | +})().then(common.mustCall()); |
| 284 | + |
240 | 285 | {
|
241 | 286 | const b = new Blob(['hello\n'], { endings: 'native' });
|
242 | 287 | assert.strictEqual(b.size, EOL.length + 5);
|
|
0 commit comments