The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as NodeSink from "@effect/platform-node-shared/NodeSink" |
| 2 | import * as NodeStream from "@effect/platform-node-shared/NodeStream" |
| 3 | import { assert, describe, it } from "@effect/vitest" |
| 4 | import { Deferred, Effect, Exit, Fiber, Option } from "effect" |
| 5 | import * as Data from "effect/Data" |
| 6 | import * as Latch from "effect/Latch" |
| 7 | import * as Queue from "effect/Queue" |
| 8 | import * as Stream from "effect/Stream" |
| 9 | import { TestClock } from "effect/testing" |
| 10 | import { createReadStream } from "fs" |
| 11 | import { join } from "path" |
| 12 | import { Writable } from "stream" |
| 13 | import * as Tar from "tar" |
| 14 | |
| 15 | const TEST_TARBALL = join(__dirname, "fixtures", "helloworld.tar.gz") |
| 16 | |
| 17 | describe("Sink", () => { |
| 18 | it.effect.each( |
| 19 | [ |
| 20 | { mode: "failure", endOnDone: undefined }, |
| 21 | { mode: "interrupt", endOnDone: undefined }, |
| 22 | { mode: "failure", endOnDone: false }, |
| 23 | { mode: "interrupt", endOnDone: false } |
| 24 | ] as const |
| 25 | )("releases owned writables on $mode (endOnDone: $endOnDone)", ({ mode, endOnDone }) => |
| 26 | Effect.gen(function*() { |
| 27 | const started = yield* Deferred.make<void>() |
| 28 | const failure = new Error("upstream failed") |
| 29 | const items: Array<string> = [] |
| 30 | const writable = new Writable({ |
| 31 | write(chunk, _encoding, callback) { |
| 32 | items.push(chunk.toString()) |
| 33 | callback() |
| 34 | } |
| 35 | }) |
| 36 | yield* Effect.addFinalizer(() => Effect.sync(() => writable.destroy())) |
| 37 | const fiber = yield* Stream.make("a").pipe( |
| 38 | Stream.concat(Stream.fromEffect(Effect.gen(function*() { |
| 39 | yield* Deferred.succeed(started, undefined) |
| 40 | return yield* (mode === "failure" ? Effect.fail(failure) : Effect.never) |
| 41 | }))), |
| 42 | Stream.run(NodeSink.fromWritable({ |
| 43 | evaluate: () => writable, |
| 44 | onError: (error) => error, |
| 45 | endOnDone |
| 46 | })), |
| 47 | Effect.forkScoped |
| 48 | ) |
| 49 | yield* Deferred.await(started) |
| 50 | if (mode === "interrupt") { |
| 51 | yield* Fiber.interrupt(fiber) |
| 52 | } |
| 53 | const exit = yield* Fiber.await(fiber) |
| 54 | if (mode === "failure") { |
| 55 | assert.deepEqual(exit, Exit.fail(failure)) |
| 56 | } else { |
| 57 | assert.isTrue(Exit.hasInterrupts(exit)) |
| 58 | } |
| 59 | assert.deepEqual(items, ["a"]) |
| 60 | // Assert before test-scope cleanup can release the writable for the sink. |
| 61 | assert.strictEqual(writable.writableEnded || writable.destroyed, endOnDone !== false) |
| 62 | })) |
| 63 | |
| 64 | it.effect.each(["already_finished", "finished_while_pulling", "finished_while_draining", "empty"] as const)( |
| 65 | "settles after normal writable finish: %s", |
| 66 | (phase) => |
| 67 | Effect.gen(function*() { |
| 68 | const entered = yield* Deferred.make<void>() |
| 69 | const release = yield* Deferred.make<void>() |
| 70 | const closed = yield* Deferred.make<void>() |
| 71 | const writing = yield* Deferred.make<() => void>() |
| 72 | const mapped = { _tag: "WritableError" } |
| 73 | const errors: Array<unknown> = [] |
| 74 | const writable = new Writable({ |
| 75 | highWaterMark: phase === "finished_while_draining" ? 1 : 16384, |
| 76 | write(_chunk, _encoding, callback) { |
| 77 | if (phase === "finished_while_draining") { |
| 78 | // Resume the test only after write() returns and the sink waits for drain. |
| 79 | queueMicrotask(() => Deferred.doneUnsafe(writing, Effect.succeed(callback))) |
| 80 | } else { |
| 81 | callback() |
| 82 | } |
| 83 | } |
| 84 | }) |
| 85 | writable.once("close", () => Deferred.doneUnsafe(closed, Effect.void)) |
| 86 | yield* Effect.addFinalizer(() => Effect.sync(() => writable.destroy())) |
| 87 | if (phase === "already_finished" || phase === "empty") { |
| 88 | writable.end() |
| 89 | yield* Deferred.await(closed) |
| 90 | } |
| 91 | const upstream = phase === "empty" ? |
| 92 | Stream.empty : |
| 93 | phase === "finished_while_pulling" ? |
| 94 | Stream.fromEffect(Effect.gen(function*() { |
| 95 | yield* Deferred.succeed(entered, undefined) |
| 96 | yield* Deferred.await(release) |
| 97 | return "a" |
| 98 | })) : |
| 99 | Stream.make("a", "b") |
| 100 | const fiber = yield* upstream.pipe( |
| 101 | Stream.run(NodeSink.fromWritable({ |
| 102 | evaluate: () => writable, |
| 103 | onError: (error) => { |
| 104 | errors.push(error) |
| 105 | return mapped |
| 106 | } |
| 107 | })), |
| 108 | Effect.exit, |
| 109 | Effect.timeoutOption("1 second"), |
| 110 | Effect.forkScoped |
| 111 | ) |
| 112 | if (phase === "finished_while_pulling") { |
| 113 | yield* Deferred.await(entered) |
| 114 | writable.end() |
| 115 | yield* Deferred.await(closed) |
| 116 | yield* Deferred.succeed(release, undefined) |
| 117 | } else if (phase === "finished_while_draining") { |
| 118 | const completeWrite = yield* Deferred.await(writing) |
| 119 | writable.end() |
| 120 | yield* Effect.sync(completeWrite) |
| 121 | yield* Deferred.await(closed) |
| 122 | } |
| 123 | // Node has finished and auto-destroyed; advance only the non-completion guard. |
| 124 | yield* TestClock.adjust("1 second") |
| 125 | assert.deepEqual(yield* Fiber.join(fiber), Option.some(phase === "empty" ? Exit.void : Exit.fail(mapped))) |
| 126 | assert.strictEqual(errors.length, phase === "empty" ? 0 : 1) |
| 127 | }) |
| 128 | ) |
| 129 | |
| 130 | it.effect("maps write errors after the writable has finished", () => |
| 131 | Effect.gen(function*() { |
| 132 | const finished = yield* Deferred.make<void>() |
| 133 | const errored = yield* Deferred.make<Error>() |
| 134 | const mapped = { _tag: "WritableError" } |
| 135 | const errors: Array<unknown> = [] |
| 136 | const writable = new Writable({ |
| 137 | autoDestroy: false, |
| 138 | write(_chunk, _encoding, callback) { |
| 139 | callback() |
| 140 | } |
| 141 | }) |
| 142 | yield* Effect.addFinalizer(() => Effect.sync(() => writable.destroy())) |
| 143 | writable.once("finish", () => Deferred.doneUnsafe(finished, Effect.void)) |
| 144 | writable.once("error", (error) => Deferred.doneUnsafe(errored, Effect.succeed(error))) |
| 145 | writable.end() |
| 146 | yield* Deferred.await(finished) |
| 147 | const fiber = yield* Stream.make("a").pipe( |
| 148 | Stream.run(NodeSink.fromWritable({ |
| 149 | evaluate: () => writable, |
| 150 | onError: (error) => { |
| 151 | errors.push(error) |
| 152 | return mapped |
| 153 | } |
| 154 | })), |
| 155 | Effect.exit, |
| 156 | Effect.timeoutOption("1 second"), |
| 157 | Effect.forkScoped |
| 158 | ) |
| 159 | const error = yield* Deferred.await(errored) |
| 160 | assert.strictEqual((error as NodeJS.ErrnoException).code, "ERR_STREAM_WRITE_AFTER_END") |
| 161 | // Node has emitted the write error; advance only the non-completion guard. |
| 162 | yield* TestClock.adjust("1 second") |
| 163 | assert.deepEqual({ result: yield* Fiber.join(fiber), errors }, { |
| 164 | result: Option.some(Exit.fail(mapped)), |
| 165 | errors: [error] |
| 166 | }) |
| 167 | })) |
| 168 | |
| 169 | it.effect("handles write errors until asynchronous destruction completes", () => |
| 170 | Effect.gen(function*() { |
| 171 | const destroying = yield* Deferred.make<() => void>() |
| 172 | const closed = yield* Deferred.make<void>() |
| 173 | const error = new Error("write failed") |
| 174 | const mapped = { _tag: "WritableError" } |
| 175 | const errors: Array<unknown> = [] |
| 176 | let handled = false |
| 177 | const writable = new Writable({ |
| 178 | write(_chunk, _encoding, callback) { |
| 179 | callback(error) |
| 180 | }, |
| 181 | destroy(error, callback) { |
| 182 | Deferred.doneUnsafe(destroying, Effect.succeed(() => callback(error))) |
| 183 | } |
| 184 | }) |
| 185 | // Prevent an unhandled error from crashing the test worker, but check that |
| 186 | // the sink itself still handles the event when destruction finally ends. |
| 187 | writable.on("error", () => { |
| 188 | handled = writable.listenerCount("error") > 1 |
| 189 | }) |
| 190 | writable.once("close", () => Deferred.doneUnsafe(closed, Effect.void)) |
| 191 | const fiber = yield* Stream.make("a").pipe( |
| 192 | Stream.run(NodeSink.fromWritable({ |
| 193 | evaluate: () => writable, |
| 194 | onError: (error) => { |
| 195 | errors.push(error) |
| 196 | return mapped |
| 197 | } |
| 198 | })), |
| 199 | Effect.exit, |
| 200 | Effect.timeoutOption("1 second"), |
| 201 | Effect.forkScoped |
| 202 | ) |
| 203 | const release = yield* Deferred.await(destroying) |
| 204 | // Cross an event-loop turn with _destroy still gated, allowing callback |
| 205 | // failure and any sink cleanup to run before Node emits the error. |
| 206 | yield* Effect.promise(() => new Promise<void>((resolve) => setImmediate(resolve))) |
| 207 | yield* Effect.sync(release) |
| 208 | yield* Deferred.await(closed) |
| 209 | yield* TestClock.adjust("1 second") |
| 210 | assert.deepEqual({ result: yield* Fiber.join(fiber), errors }, { |
| 211 | result: Option.some(Exit.fail(mapped)), |
| 212 | errors: [error] |
| 213 | }) |
| 214 | assert.isTrue(handled, "the sink must handle the delayed Node error event") |
| 215 | })) |
| 216 | |
| 217 | it.effect.each(["drain", "final", "already_closed"] as const)( |
| 218 | "settles when destroyed without an error: %s", |
| 219 | (phase) => |
| 220 | Effect.gen(function*() { |
| 221 | const entered = yield* Deferred.make<void>() |
| 222 | const closed = yield* Deferred.make<void>() |
| 223 | const mapped = { _tag: "WritableError" } |
| 224 | const errors: Array<unknown> = [] |
| 225 | const writable = new Writable({ |
| 226 | highWaterMark: 1, |
| 227 | write(_chunk, _encoding, callback) { |
| 228 | if (phase === "drain") { |
| 229 | queueMicrotask(() => Deferred.doneUnsafe(entered, Effect.void)) |
| 230 | } else { |
| 231 | callback() |
| 232 | } |
| 233 | }, |
| 234 | final() { |
| 235 | queueMicrotask(() => Deferred.doneUnsafe(entered, Effect.void)) |
| 236 | } |
| 237 | }) |
| 238 | writable.once("close", () => Deferred.doneUnsafe(closed, Effect.void)) |
| 239 | yield* Effect.addFinalizer(() => Effect.sync(() => writable.destroy())) |
| 240 | if (phase === "already_closed") { |
| 241 | writable.destroy() |
| 242 | yield* Deferred.await(closed) |
| 243 | } |
| 244 | const fiber = yield* Stream.make("a", "b").pipe( |
| 245 | Stream.run(NodeSink.fromWritable({ |
| 246 | evaluate: () => writable, |
| 247 | onError: (error) => { |
| 248 | errors.push(error) |
| 249 | return mapped |
| 250 | } |
| 251 | })), |
| 252 | Effect.exit, |
| 253 | Effect.timeoutOption("1 second"), |
| 254 | Effect.forkScoped |
| 255 | ) |
| 256 | if (phase !== "already_closed") { |
| 257 | // Let the sink enter its drain/finish wait before destroying the stream. |
| 258 | yield* Deferred.await(entered) |
| 259 | writable.destroy() |
| 260 | yield* Deferred.await(closed) |
| 261 | } |
| 262 | // Node has closed; advance only the virtual non-completion guard. |
| 263 | yield* TestClock.adjust("1 second") |
| 264 | assert.deepEqual(yield* Fiber.join(fiber), Option.some(phase === "final" ? Exit.void : Exit.fail(mapped))) |
| 265 | if (phase === "final") { |
| 266 | assert.deepEqual(errors, []) |
| 267 | } else { |
| 268 | assert.strictEqual(errors.length, 1) |
| 269 | assert.strictEqual((errors[0] as NodeJS.ErrnoException).code, "ERR_STREAM_PREMATURE_CLOSE") |
| 270 | } |
| 271 | }) |
| 272 | ) |
| 273 | |
| 274 | it.effect("does not resume a selected drain callback after interruption", () => |
| 275 | Effect.gen(function*() { |
| 276 | const items: Array<string> = [] |
| 277 | const entered = yield* Deferred.make<() => void>() |
| 278 | const drained = yield* Deferred.make<void>() |
| 279 | const controller = new AbortController() |
| 280 | const writable = new Writable({ |
| 281 | highWaterMark: 1, |
| 282 | write(chunk, _encoding, callback) { |
| 283 | items.push(chunk.toString()) |
| 284 | if (chunk.toString() === "a") { |
| 285 | queueMicrotask(() => Deferred.doneUnsafe(entered, Effect.succeed(callback))) |
| 286 | } else { |
| 287 | callback() |
| 288 | } |
| 289 | } |
| 290 | }) |
| 291 | yield* Effect.addFinalizer(() => |
| 292 | Effect.sync(() => { |
| 293 | controller.abort() |
| 294 | writable.destroy() |
| 295 | }) |
| 296 | ) |
| 297 | writable.once("drain", () => controller.abort()) |
| 298 | Effect.runCallback( |
| 299 | Stream.make("a", "b").pipe( |
| 300 | Stream.run(NodeSink.fromWritable({ evaluate: () => writable, onError: (error) => error })) |
| 301 | ), |
| 302 | { signal: controller.signal, onExit: () => {} } |
| 303 | ) |
| 304 | const release = yield* Deferred.await(entered) |
| 305 | assert.deepEqual(items, ["a"]) |
| 306 | writable.once("drain", () => { |
| 307 | queueMicrotask(() => Deferred.doneUnsafe(drained, Effect.void)) |
| 308 | }) |
| 309 | yield* Effect.sync(release) |
| 310 | yield* Deferred.await(drained) |
| 311 | assert.deepEqual(items, ["a"]) |
| 312 | })) |
| 313 | |
| 314 | it.effect.each(["normal_final", "write_error", "final_error"] as const)( |
| 315 | "writable lifecycle: %s", |
| 316 | (mode) => |
| 317 | Effect.gen(function*() { |
| 318 | const error = new Error(mode) |
| 319 | const mapped = { _tag: "WritableError", cause: error } |
| 320 | const observed: Array<unknown> = [] |
| 321 | const mappedErrors: Array<unknown> = [] |
| 322 | const closed = yield* Deferred.make<void>() |
| 323 | const items: Array<string> = [] |
| 324 | let finalized = false |
| 325 | const writable = new Writable({ |
| 326 | write(chunk, _encoding, callback) { |
| 327 | items.push(chunk.toString()) |
| 328 | callback(mode === "write_error" ? error : null) |
| 329 | }, |
| 330 | final(callback) { |
| 331 | finalized = true |
| 332 | callback(mode === "final_error" ? error : null) |
| 333 | } |
| 334 | }) |
| 335 | // Observe Node errors without handling them on behalf of the sink. |
| 336 | writable.on("error", (error) => observed.push(error)) |
| 337 | writable.once("close", () => Deferred.doneUnsafe(closed, Effect.void)) |
| 338 | yield* Effect.addFinalizer(() => Effect.sync(() => writable.destroy())) |
| 339 | const fiber = yield* Stream.make("a", "b").pipe( |
| 340 | Stream.run(NodeSink.fromWritable({ |
| 341 | evaluate: () => writable, |
| 342 | onError: (error) => { |
| 343 | mappedErrors.push(error) |
| 344 | return mapped |
| 345 | } |
| 346 | })), |
| 347 | Effect.exit, |
| 348 | Effect.timeoutOption("1 second"), |
| 349 | Effect.forkScoped |
| 350 | ) |
| 351 | yield* Deferred.await(closed) |
| 352 | // The writable has settled; advance only the virtual non-completion guard. |
| 353 | yield* TestClock.adjust("1 second") |
| 354 | assert.deepEqual(observed, mode === "normal_final" ? [] : [error]) |
| 355 | assert.strictEqual(finalized, mode !== "write_error") |
| 356 | assert.deepEqual(items, mode === "write_error" ? ["a"] : ["a", "b"]) |
| 357 | assert.deepEqual({ result: yield* Fiber.join(fiber), mappedErrors }, { |
| 358 | result: Option.some(mode === "normal_final" ? Exit.void : Exit.fail(mapped)), |
| 359 | mappedErrors: mode === "normal_final" ? [] : [error] |
| 360 | }) |
| 361 | }) |
| 362 | ) |
| 363 | |
| 364 | it.effect.each(["error", "interrupt"] as const)( |
| 365 | "cleans up finalization listeners on %s", |
| 366 | (mode) => |
| 367 | Effect.gen(function*() { |
| 368 | const finalizing = yield* Deferred.make<(error?: Error | null) => void>() |
| 369 | const error = new Error("finalization failed") |
| 370 | const writable = new Writable({ |
| 371 | write(_chunk, _encoding, callback) { |
| 372 | callback() |
| 373 | }, |
| 374 | final(callback) { |
| 375 | queueMicrotask(() => Deferred.doneUnsafe(finalizing, Effect.succeed(callback))) |
| 376 | } |
| 377 | }) |
| 378 | const observed: Array<unknown> = [] |
| 379 | writable.on("error", (error) => observed.push(error)) |
| 380 | yield* Effect.addFinalizer(() => Effect.sync(() => writable.destroy())) |
| 381 | const fiber = yield* Stream.make("a").pipe( |
| 382 | Stream.run(NodeSink.fromWritable({ evaluate: () => writable, onError: (error) => error })), |
| 383 | Effect.forkScoped |
| 384 | ) |
| 385 | const release = yield* Deferred.await(finalizing) |
| 386 | assert.strictEqual(writable.listenerCount("finish"), 1) |
| 387 | if (mode === "error") { |
| 388 | yield* Effect.sync(() => release(error)) |
| 389 | assert.deepEqual(yield* Fiber.await(fiber), Exit.fail(error)) |
| 390 | } else { |
| 391 | yield* Fiber.interrupt(fiber) |
| 392 | } |
| 393 | assert.strictEqual(writable.listenerCount("finish"), 0) |
| 394 | assert.strictEqual(writable.listenerCount("error"), 1) |
| 395 | assert.deepEqual(observed, mode === "error" ? [error] : []) |
| 396 | if (mode === "interrupt") { |
| 397 | yield* Effect.sync(() => release()) |
| 398 | } |
| 399 | }) |
| 400 | ) |
| 401 | |
| 402 | it.effect("should write to a stream", () => |
| 403 | Effect.gen(function*() { |
| 404 | const items: Array<string> = [] |
| 405 | const destroyLatch = yield* Latch.make() |
| 406 | yield* Stream.make("a", "b", "c").pipe( |
| 407 | Stream.run(NodeSink.fromWritable({ |
| 408 | evaluate: () => |
| 409 | new Writable({ |
| 410 | construct(callback) { |
| 411 | callback() |
| 412 | }, |
| 413 | write(chunk, _encoding, callback) { |
| 414 | items.push(chunk.toString()) |
| 415 | callback() |
| 416 | }, |
| 417 | destroy(_error, callback) { |
| 418 | destroyLatch.openUnsafe() |
| 419 | callback(null) |
| 420 | } |
| 421 | }), |
| 422 | onError: () => "error" |
| 423 | })) |
| 424 | ) |
| 425 | assert.deepEqual(items, ["a", "b", "c"]) |
| 426 | yield* destroyLatch.await |
| 427 | })) |
| 428 | |
| 429 | it.effect("write error", () => |
| 430 | Effect.gen(function*() { |
| 431 | const items: Array<string> = [] |
| 432 | const sink = NodeSink.fromWritable({ |
| 433 | evaluate: () => |
| 434 | new Writable({ |
| 435 | construct(callback) { |
| 436 | callback() |
| 437 | }, |
| 438 | write(chunk, _encoding, callback) { |
| 439 | items.push(chunk.toString()) |
| 440 | callback() |
| 441 | }, |
| 442 | destroy(_error, callback) { |
| 443 | callback(null) |
| 444 | } |
| 445 | }), |
| 446 | onError: () => "error" |
| 447 | }) |
| 448 | const result = yield* Stream.fail("a").pipe(Stream.run(sink), Effect.flip) |
| 449 | assert.deepEqual(items, []) |
| 450 | assert.strictEqual(result, "a") |
| 451 | })) |
| 452 | |
| 453 | it.live("endOnClose false", () => |
| 454 | Effect.gen(function*() { |
| 455 | const items: Array<string> = [] |
| 456 | let destroyed = false |
| 457 | const sink = NodeSink.fromWritable({ |
| 458 | evaluate: () => |
| 459 | new Writable({ |
| 460 | construct(callback) { |
| 461 | callback() |
| 462 | }, |
| 463 | write(chunk, _encoding, callback) { |
| 464 | items.push(chunk.toString()) |
| 465 | callback() |
| 466 | }, |
| 467 | destroy(_error, callback) { |
| 468 | destroyed = true |
| 469 | callback(null) |
| 470 | } |
| 471 | }), |
| 472 | onError: () => "error", |
| 473 | endOnDone: false |
| 474 | }) |
| 475 | yield* Stream.run(Stream.make("a", "b", "c"), sink) |
| 476 | yield* Effect.sleep(10) |
| 477 | assert.deepEqual(items, ["a", "b", "c"]) |
| 478 | assert.strictEqual(destroyed, false) |
| 479 | })) |
| 480 | |
| 481 | it.effect("should handle non-compliant node streams", () => |
| 482 | Effect.gen(function*() { |
| 483 | const stream = NodeStream.fromReadable<Uint8Array, "error">({ |
| 484 | evaluate: () => createReadStream(TEST_TARBALL), |
| 485 | onError: () => "error" |
| 486 | }) |
| 487 | const items = yield* entries(stream).pipe( |
| 488 | Stream.flatMap((entry) => |
| 489 | NodeStream.fromReadable({ |
| 490 | evaluate: () => (entry as any), |
| 491 | onError: (error) => new TarError({ error }) |
| 492 | }).pipe( |
| 493 | Stream.map((content) => ({ |
| 494 | path: entry.path, |
| 495 | content: Buffer.from(content).toString("utf-8") |
| 496 | })) |
| 497 | ) |
| 498 | ), |
| 499 | Stream.runCollect |
| 500 | ) |
| 501 | assert.deepEqual(items, [ |
| 502 | { path: "./tar/world.txt", content: "world\n" }, |
| 503 | { path: "./tar/hello.txt", content: "hello\n" } |
| 504 | ]) |
| 505 | })) |
| 506 | }) |
| 507 | |
| 508 | class TarError extends Data.TaggedError("TarError")<{ |
| 509 | readonly error: unknown |
| 510 | }> {} |
| 511 | |
| 512 | const entries = <R, E>( |
| 513 | input: Stream.Stream<Uint8Array, E, R> |
| 514 | ): Stream.Stream<Tar.ReadEntry, TarError | E, R> => |
| 515 | Effect.gen(function*() { |
| 516 | const parser = new Tar.Parser() |
| 517 | |
| 518 | yield* input.pipe( |
| 519 | Stream.run( |
| 520 | NodeSink.fromWritable({ |
| 521 | evaluate: () => parser, |
| 522 | onError: (error) => new TarError({ error }) |
| 523 | }) |
| 524 | ), |
| 525 | Effect.forkScoped |
| 526 | ) |
| 527 | |
| 528 | return Stream.callback<Tar.ReadEntry, TarError>((queue) => |
| 529 | Effect.sync(() => { |
| 530 | parser.on("entry", (entry) => { |
| 531 | Queue.offerUnsafe(queue, entry) |
| 532 | }) |
| 533 | parser.on("close", () => { |
| 534 | Queue.endUnsafe(queue) |
| 535 | }) |
| 536 | }) |
| 537 | ) |
| 538 | }).pipe(Stream.unwrap) |