import Promise from '../promise'; import { Sink } from './WritableStream'; // Since this Sink is doing no asynchronous operations, // use a single resolved promise for all returned promises. let resolved = Promise.resolve(); /** * A WritableStream sink that collects the chunks it receives and * stores them into an array. Use the chunks property to retrieve * the collection of chunks. */ export default class ArraySink implements Sink { chunks: T[]; abort(reason: any): Promise { return resolved; } close(): Promise { return Promise.resolve(); } start(error: () => void): Promise { this.chunks = []; return resolved; } write(chunk: T): Promise { if (chunk) { this.chunks.push(chunk); } return resolved; } }