I have no idea if this works lol

This commit is contained in:
May 2023-12-25 16:25:45 -08:00
parent 033295ce58
commit 4c77605b98

View file

@ -109,6 +109,7 @@ namespace StreamHelpers {
filled: number = 0 filled: number = 0
buffer: UploadStream[] = [] buffer: UploadStream[] = []
messages: string[] = [] messages: string[] = []
writable?: Writable
private newmessage_debounce : boolean = true private newmessage_debounce : boolean = true
@ -125,12 +126,17 @@ namespace StreamHelpers {
this.newmessage_debounce = false this.newmessage_debounce = false
let streams = [] let streams = []
let sbuf = this
// can't think of a better way to do // can't think of a better way to do
for (let i = 0; i < streamCount; i++) { for (let i = 0; i < streamCount; i++) {
streams.push({ streams.push({
uploaded: 0, uploaded: 0,
stream: new Readable({}) stream: new Readable({
read() {
sbuf.writable!.emit("drain");
}
})
}) })
} }
@ -146,6 +152,8 @@ namespace StreamHelpers {
if (this.buffer[0]) return this.buffer[0] if (this.buffer[0]) return this.buffer[0]
else { else {
// startmessage.... idk // startmessage.... idk
await this.startMessage(0);
return this.buffer[0]
} }
} }
@ -210,14 +218,14 @@ export default class Files {
let buf = new StreamHelpers.StreamBuffer(this.api, metadata.size) let buf = new StreamHelpers.StreamBuffer(this.api, metadata.size)
let fs_obj = this let fs_obj = this
return new Writable({ let wt = new Writable({
async write(data: Buffer) { async write(data: Buffer) {
let positionInBuf = 0 let positionInBuf = 0
while (positionInBuf < data.byteLength) { while (positionInBuf < data.byteLength) {
let ns = (await buf.getNextStream().catch(e => { let ns = (await buf.getNextStream().catch(e => {
return e return e
})) })) as Error | undefined | StreamHelpers.UploadStream
if (!ns || ns instanceof Error) { if (!ns || ns instanceof Error) {
this.destroy(ns) this.destroy(ns)
return return
@ -241,9 +249,14 @@ export default class Files {
return return
} }
} }
return false
} }
}) })
buf.writable = wt;
return wt
} }
/** /**