(message)
| 69 | }); |
| 70 | |
| 71 | async function init(message) { |
| 72 | let codecStream; |
| 73 | try { |
| 74 | const { options, config } = message; |
| 75 | if (!options.useCompressionStream) { |
| 76 | try { |
| 77 | await self.initModule(message.config); |
| 78 | } catch { |
| 79 | options.useCompressionStream = true; |
| 80 | } |
| 81 | } |
| 82 | config.CompressionStream = self.CompressionStream; |
| 83 | config.DecompressionStream = self.DecompressionStream; |
| 84 | const strategy = { highWaterMark: 1 }; |
| 85 | const readable = message.readable || new ReadableStream({ |
| 86 | async pull(controller) { |
| 87 | const result = new Promise(resolve => pendingPullMessages.set(messageId, resolve)); |
| 88 | sendMessage({ type: MESSAGE_PULL, messageId }); |
| 89 | messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER; |
| 90 | const { value, done } = await result; |
| 91 | controller.enqueue(value); |
| 92 | if (done) { |
| 93 | controller.close(); |
| 94 | } |
| 95 | } |
| 96 | }, strategy); |
| 97 | const writable = message.writable || new WritableStream({ |
| 98 | async write(value) { |
| 99 | let resolveAckData; |
| 100 | const ackData = new Promise(resolve => resolveAckData = resolve); |
| 101 | pendingDataMessages.set(messageId, resolveAckData); |
| 102 | sendMessage({ type: MESSAGE_DATA, value, messageId }); |
| 103 | messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER; |
| 104 | await ackData; |
| 105 | } |
| 106 | }, strategy); |
| 107 | const codecStream = new CodecStream(options, config); |
| 108 | abortController = new AbortController(); |
| 109 | const { signal } = abortController; |
| 110 | await readable |
| 111 | .pipeThrough(codecStream) |
| 112 | .pipeThrough(new ChunkStream(config.chunkSize)) |
| 113 | .pipeTo(writable, { signal, preventClose: true, preventAbort: true }); |
| 114 | await writable.getWriter().close(); |
| 115 | const { |
| 116 | signature, |
| 117 | inputSize, |
| 118 | outputSize |
| 119 | } = codecStream; |
| 120 | sendMessage({ |
| 121 | type: MESSAGE_CLOSE, |
| 122 | result: { |
| 123 | signature, |
| 124 | inputSize, |
| 125 | outputSize |
| 126 | } |
| 127 | }); |
| 128 | } catch (error) { |
no test coverage detected
searching dependent graphs…