mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
feat(runtime): web streams in fs & net APIs (#13615)
This commit adds `readable` and `writable` properties to `Deno.File` and `Deno.Conn`. This makes it very simple to use files and network sockets with fetch or the native HTTP server.
This commit is contained in:
parent
7b893bd57f
commit
bdc8006a36
7 changed files with 337 additions and 84 deletions
|
@ -6,10 +6,12 @@
|
|||
const { read, readSync, write, writeSync } = window.__bootstrap.io;
|
||||
const { ftruncate, ftruncateSync, fstat, fstatSync } = window.__bootstrap.fs;
|
||||
const { pathFromURL } = window.__bootstrap.util;
|
||||
const { readableStreamForRid, writableStreamForRid } =
|
||||
window.__bootstrap.streamUtils;
|
||||
const {
|
||||
ArrayPrototypeFilter,
|
||||
Error,
|
||||
ObjectValues,
|
||||
ArrayPrototypeFilter,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
function seekSync(
|
||||
|
@ -77,6 +79,9 @@
|
|||
class File {
|
||||
#rid = 0;
|
||||
|
||||
#readable;
|
||||
#writable;
|
||||
|
||||
constructor(rid) {
|
||||
this.#rid = rid;
|
||||
}
|
||||
|
@ -128,9 +133,25 @@
|
|||
close() {
|
||||
core.close(this.rid);
|
||||
}
|
||||
|
||||
get readable() {
|
||||
if (this.#readable === undefined) {
|
||||
this.#readable = readableStreamForRid(this.rid);
|
||||
}
|
||||
return this.#readable;
|
||||
}
|
||||
|
||||
get writable() {
|
||||
if (this.#writable === undefined) {
|
||||
this.#writable = writableStreamForRid(this.rid);
|
||||
}
|
||||
return this.#writable;
|
||||
}
|
||||
}
|
||||
|
||||
class Stdin {
|
||||
#readable;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
|
@ -149,9 +170,18 @@
|
|||
close() {
|
||||
core.close(this.rid);
|
||||
}
|
||||
|
||||
get readable() {
|
||||
if (this.#readable === undefined) {
|
||||
this.#readable = readableStreamForRid(this.rid);
|
||||
}
|
||||
return this.#readable;
|
||||
}
|
||||
}
|
||||
|
||||
class Stdout {
|
||||
#writable;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
|
@ -170,9 +200,18 @@
|
|||
close() {
|
||||
core.close(this.rid);
|
||||
}
|
||||
|
||||
get writable() {
|
||||
if (this.#writable === undefined) {
|
||||
this.#writable = writableStreamForRid(this.rid);
|
||||
}
|
||||
return this.#writable;
|
||||
}
|
||||
}
|
||||
|
||||
class Stderr {
|
||||
#writable;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
|
@ -191,6 +230,13 @@
|
|||
close() {
|
||||
core.close(this.rid);
|
||||
}
|
||||
|
||||
get writable() {
|
||||
if (this.#writable === undefined) {
|
||||
this.#writable = writableStreamForRid(this.rid);
|
||||
}
|
||||
return this.#writable;
|
||||
}
|
||||
}
|
||||
|
||||
const stdin = new Stdin();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue