UNPKG

1.2 kBSource Map (JSON)View Raw
1{"version":3,"file":"reader.js","sourceRoot":"","sources":["../../../../src/link/http/iterators/reader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAO/D,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,MAAsC;IAEtC,IAAM,QAAQ,GAAsB;QAClC,IAAI;YACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;IAEF,IAAI,yBAAyB,EAAE;QAC7B,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;KACH;IAED,OAAO,QAAoC,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Original source:\n * https://github.com/kmalakoff/response-iterator/blob/master/src/iterators/reader.ts\n */\n\nimport { canUseAsyncIteratorSymbol } from \"../../../utilities\";\n\ninterface ReaderIterator<T> {\n next(): Promise<ReadableStreamReadResult<T>>;\n [Symbol.asyncIterator]?(): AsyncIterator<T>;\n}\n\nexport default function readerIterator<T>(\n reader: ReadableStreamDefaultReader<T>\n): AsyncIterableIterator<T> {\n const iterator: ReaderIterator<T> = {\n next() {\n return reader.read();\n },\n };\n\n if (canUseAsyncIteratorSymbol) {\n iterator[Symbol.asyncIterator] = function (): AsyncIterator<T> {\n return this;\n };\n }\n\n return iterator as AsyncIterableIterator<T>;\n}\n"]}
\No newline at end of file