silverwolf-x's picture
download
raw
658 Bytes
import * as stream from 'stream'
import { Deferred, sleep } from './sleep'
export function Readable(write: number) {
const encoder = new TextEncoder()
const cleanedUp = new Deferred()
const aborted = new Deferred()
let i = 0
const readable = {
finished: Promise.all([cleanedUp.promise, aborted.promise]).then(() => i),
abort() {
aborted.resolve()
},
stream: new stream.Readable({
async read() {
if (i >= write) {
return
}
await sleep(100)
this.push(encoder.encode(String(i++)))
},
destroy() {
cleanedUp.resolve()
},
}),
}
return readable
}

Xet Storage Details

Size:
658 Bytes
·
Xet hash:
bfb5bd154a249f083071422537d17909f976f9bfaf6164cc534fd1a19dc53002

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.