| 67 | } |
| 68 | |
| 69 | export async function pipeStream(read, write, abort) { |
| 70 | if (window.WritableStream && read.pipeTo) { |
| 71 | const abortController = new AbortController(); |
| 72 | if (abort) abort.abort = abortController.abort.bind(abortController); |
| 73 | await read.pipeTo(write, abortController); |
| 74 | } else { |
| 75 | const writer = write.getWriter(); |
| 76 | if (abort) abort.abort = writer.abort.bind(writer); |
| 77 | const reader = read.getReader(); |
| 78 | while (1) { |
| 79 | const readResult = await reader.read(); |
| 80 | if (readResult.done) { |
| 81 | writer.close(); |
| 82 | break; |
| 83 | } else writer.write(readResult.value); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // https://github.com/andrasq/node-mongoid-js/blob/master/mongoid.js |
| 89 | export function mongoId(idstring: string) { |