| 174 | } |
| 175 | |
| 176 | async function runPull(compressFactory) { |
| 177 | const fh = await fs.promises.open(filename, 'r'); |
| 178 | try { |
| 179 | // Stateless transform: uppercase each chunk in the batch |
| 180 | const upper = (chunks) => { |
| 181 | if (chunks === null) return null; |
| 182 | const out = new Array(chunks.length); |
| 183 | for (let j = 0; j < chunks.length; j++) { |
| 184 | out[j] = uppercaseChunk(chunks[j]); |
| 185 | } |
| 186 | return out; |
| 187 | }; |
| 188 | |
| 189 | const readable = fh.pull(upper, compressFactory()); |
| 190 | |
| 191 | let totalBytes = 0; |
| 192 | for await (const chunks of readable) { |
| 193 | for (let i = 0; i < chunks.length; i++) { |
| 194 | totalBytes += chunks[i].byteLength; |
| 195 | } |
| 196 | } |
| 197 | return totalBytes; |
| 198 | } finally { |
| 199 | await fh.close(); |
| 200 | } |
| 201 | } |