chunk.ts 484 B

123456789101112131415
  1. import { TransformStream } from "./stream.js";
  2. export class ChunkStream extends TransformStream<Uint8Array, Uint8Array>{
  3. public constructor(size: number) {
  4. super({
  5. transform(chunk, controller) {
  6. for (let start = 0; start < chunk.byteLength;) {
  7. const end = start + size;
  8. controller.enqueue(chunk.subarray(start, end));
  9. start = end;
  10. }
  11. }
  12. });
  13. }
  14. }