awh fuck it

This commit is contained in:
May 2023-12-26 16:37:04 -08:00
parent 8fb2a55bdd
commit b80ddd26e7
3 changed files with 20 additions and 7 deletions

View file

@ -75,24 +75,32 @@ program.command("upload")
if (!(writable instanceof Writable)) if (!(writable instanceof Writable))
throw JSON.stringify(writable, null, 3) throw JSON.stringify(writable, null, 3)
;(await fs.createReadStream(file)).pipe(
writable
)
console.log(`started: ${file}`) console.log(`started: ${file}`)
writable.on("drain", () => { writable.on("drain", () => {
console.log("Drain") console.log("Drained")
}) })
writable.on("finish", () => { writable.on("finish", () => {
console.log("Finished!") console.log("Finished!")
}) })
writable.on("pipe", () => {
console.log("Piped")
})
writable.on("error", (e) => { writable.on("error", (e) => {
console.error(e) console.error(e)
}) })
writable.on("close", () => {
console.log("Closed.")
})
;(await fs.createReadStream(file)).pipe(
writable
)
}) })

View file

@ -124,6 +124,8 @@ namespace StreamHelpers {
private async startMessage(streamCount: number): Promise<UploadStream[] | undefined> { private async startMessage(streamCount: number): Promise<UploadStream[] | undefined> {
console.log(`Starting a message with ${streamCount} stream(s)`)
if (!this.newmessage_debounce) return if (!this.newmessage_debounce) return
this.newmessage_debounce = false this.newmessage_debounce = false
@ -136,6 +138,7 @@ namespace StreamHelpers {
uploaded: 0, uploaded: 0,
stream: new Readable({ stream: new Readable({
read() { read() {
console.log('FD is reading stream. Emitting drain...')
sbuf.writable!.emit("drain"); sbuf.writable!.emit("drain");
} }
}) })
@ -151,6 +154,7 @@ namespace StreamHelpers {
} }
async getNextStream() { async getNextStream() {
console.log("Getting next stream...")
if (this.buffer[0]) return this.buffer[0] if (this.buffer[0]) return this.buffer[0]
else { else {
// startmessage.... idk // startmessage.... idk
@ -227,6 +231,7 @@ export default class Files {
let wt = new Writable({ let wt = new Writable({
async write(data: Buffer) { async write(data: Buffer) {
console.log("Write to stream attempted")
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 => {
@ -249,7 +254,7 @@ export default class Files {
positionInBuf += bytesToPush positionInBuf += bytesToPush
if (ns.uploaded == fs_obj.config.maxDiscordFileSize) if (ns.uploaded == fs_obj.config.maxDiscordFileSize)
buf.buffer.splice(0, 1)[0]?.stream.destroy() buf.buffer.splice(0, 1)[0]?.stream.push(null)
if (buf.filled == buf.targetSize) { if (buf.filled == buf.targetSize) {
this.destroy() this.destroy()