| 24 | } |
| 25 | |
| 26 | function testPullSyncStatefulTransform() { |
| 27 | const source = fromSync('data'); |
| 28 | const stateful = { |
| 29 | transform: function*(source) { |
| 30 | for (const chunks of source) { |
| 31 | if (chunks === null) { |
| 32 | // Flush: emit trailer |
| 33 | yield new TextEncoder().encode('-END'); |
| 34 | continue; |
| 35 | } |
| 36 | for (const chunk of chunks) { |
| 37 | yield chunk; |
| 38 | } |
| 39 | } |
| 40 | }, |
| 41 | }; |
| 42 | const result = pullSync(source, stateful); |
| 43 | const data = new TextDecoder().decode(bytesSync(result)); |
| 44 | assert.strictEqual(data, 'data-END'); |
| 45 | } |
| 46 | |
| 47 | function testPullSyncChainedTransforms() { |
| 48 | const addExcl = (chunks) => { |