const readableStream = <T extends Uint8Array>(reader: ReadableStreamDefaultReader<T>) => {
return Stream.async((emit) => { /* <--- Type 'Effect<Uint8Array, string | UnknownException, never>' is not assignable to type 'Effect<void, never, never>'.
Type 'Uint8Array' is not assignable to type 'void'.*/
const generator = Effect.fn("effectReadableStreamGenerator")(function* () {
let received = 0
const chunks: Uint8Array[] = []
while (true) {
const { done, value } = yield* Effect.tryPromise(() => reader.read())
if (!value) return yield* Effect.fail("something went wrong")
received += value.length
chunks.push(value)
if (done) {
const blob = new Uint8Array(
chunks.reduce((acc, chunk) => acc + chunk.length, 0),
)
chunks.forEach((chunk, i) => blob.set(chunk, i))
return yield* Effect.succeed(blob)
} else {
emit(Effect.succeed(Chunk.of({ received })))
}
}
return yield* Effect.never
})()
return generator
})
}
const readableStream = <T extends Uint8Array>(reader: ReadableStreamDefaultReader<T>) => {
return Stream.async((emit) => { /* <--- Type 'Effect<Uint8Array, string | UnknownException, never>' is not assignable to type 'Effect<void, never, never>'.
Type 'Uint8Array' is not assignable to type 'void'.*/
const generator = Effect.fn("effectReadableStreamGenerator")(function* () {
let received = 0
const chunks: Uint8Array[] = []
while (true) {
const { done, value } = yield* Effect.tryPromise(() => reader.read())
if (!value) return yield* Effect.fail("something went wrong")
received += value.length
chunks.push(value)
if (done) {
const blob = new Uint8Array(
chunks.reduce((acc, chunk) => acc + chunk.length, 0),
)
chunks.forEach((chunk, i) => blob.set(chunk, i))
return yield* Effect.succeed(blob)
} else {
emit(Effect.succeed(Chunk.of({ received })))
}
}
return yield* Effect.never
})()
return generator
})
}