unfinished but

i'm in class and i'm running out of time so I'm just gonna commit what I have in the web editor
This commit is contained in:
May 2024-03-01 10:59:51 -08:00 committed by GitHub
parent c6e9e25973
commit 31f95ea41d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -125,13 +125,28 @@ export class UploadStream extends Writable {
// implementing some stuff // implementing some stuff
_write(data: Buffer, encoding: string, callback: () => void) { async _write(data: Buffer, encoding: string, callback: () => void) {
console.log("Write to stream attempted") console.log("Write to stream attempted")
this.getNextStream().then(ns => { if (filled + data.byteLength > (this.files.config.maxDiscordFileSize*this.files.config.maxDiscordFiles))
if (ns) {ns.push(data); callback()} else this.end(); return this.destroy(new WebError(413, "maximum file size exceeded"))
console.log(`pushed... ${ns ? "ns exists" : "ns doesn't exist"}... ${data.byteLength} byte chunk`);
return // cut up the buffer into message sized chunks
})
let progress = 0
while (progress < data.byteLength) {
let capture = Math.min(
this.config.maxDiscordFileSize - (this.filled % this.config.maxDiscordFileSize),
chunk.byteLength
)
console.log(`Capturing ${capture} bytes, ${chunk.subarray(position, capture).byteLength}`)
let nextStream = await this.getNextStream()
nextStream.push( chunk.subarray(position, capture) )
console.log(`pushed ${data.byteLength} byte chunk`);
progress += capture, this.filled += capture
}
callback()
} }
_destroy(error: Error | null) { _destroy(error: Error | null) {
@ -217,10 +232,12 @@ export class UploadStream extends Writable {
if (!this.newmessage_debounce) return if (!this.newmessage_debounce) return
this.newmessage_debounce = false this.newmessage_debounce = false
let wrt = this
let stream = new Readable({ let stream = new Readable({
read() { read() {
console.log("Read called. Emitting drain") console.log("Read called. Emitting drain")
this.emit("drain") wrt.emit("drain")
} }
}) })
stream.pause() stream.pause()