Current section

Files

Jump to
gossamer src gossamer readable_stream.ffi.mjs
Raw

src/gossamer/readable_stream.ffi.mjs

// src/gossamer/readable_stream/stream_pipe_option.ts
import * as $streamPipeOption from "./readable_stream/stream_pipe_option.mjs";
// src/utils/list.ts
import {
List$Empty,
List$isNonEmpty,
List$NonEmpty,
List$NonEmpty$first,
List$NonEmpty$rest
} from "../../prelude.mjs";
function toArray(list) {
const array = [];
let current = list;
while (List$isNonEmpty(current)) {
array.push(List$NonEmpty$first(current));
current = List$NonEmpty$rest(current);
}
return array;
}
// src/gossamer/readable_stream/stream_pipe_option.ts
function toStreamPipeOptions(options) {
const result = {};
for (const option of toArray(options)) {
if ($streamPipeOption.StreamPipeOption$isPreventAbort(option)) {
result.preventAbort = true;
} else if ($streamPipeOption.StreamPipeOption$isPreventCancel(option)) {
result.preventCancel = true;
} else if ($streamPipeOption.StreamPipeOption$isPreventClose(option)) {
result.preventClose = true;
} else if ($streamPipeOption.StreamPipeOption$isSignal(option)) {
result.signal = $streamPipeOption.StreamPipeOption$Signal$0(option);
}
}
return result;
}
// src/gossamer/readable_stream/underlying_source.ts
import * as $underlyingSource from "./readable_stream/underlying_source.mjs";
function toUnderlyingSource(options) {
const result = {};
for (const option of options) {
if ($underlyingSource.UnderlyingSource$isStart(option)) {
result.start = $underlyingSource.UnderlyingSource$Start$0(option);
} else if ($underlyingSource.UnderlyingSource$isPull(option)) {
result.pull = $underlyingSource.UnderlyingSource$Pull$0(option);
} else if ($underlyingSource.UnderlyingSource$isCancel(option)) {
result.cancel = $underlyingSource.UnderlyingSource$Cancel$0(option);
}
}
return result;
}
// src/gossamer/readable_stream.ffi.ts
var new_ = (source) => {
return new ReadableStream(toUnderlyingSource(toArray(source)));
};
var from = (iterable) => {
return ReadableStream.from(iterable);
};
var is_locked = (stream) => {
return stream.locked;
};
var cancel = (stream, reason) => {
return stream.cancel(reason).then(() => void 0);
};
var get_reader = (stream) => {
return stream.getReader();
};
var get_byob_reader = (stream) => {
return stream.getReader({ mode: "byob" });
};
var pipe_through = (stream, [readable, writable], options) => {
return stream.pipeThrough(
{ readable, writable },
toStreamPipeOptions(options)
);
};
var pipe_to = (stream, destination, options) => {
return stream.pipeTo(
destination,
toStreamPipeOptions(options)
).then(() => void 0);
};
var tee = (stream) => {
return stream.tee();
};
var async_iterator = (stream) => {
return stream.values();
};
export {
async_iterator,
cancel,
from,
get_byob_reader,
get_reader,
is_locked,
new_,
pipe_through,
pipe_to,
tee
};