From 203dda2abbe3e2d89252842ee14aba09309700fa Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sun, 29 Nov 2020 11:54:11 -0600 Subject: [PATCH] Fix file write streaming logic --- Streamer.js | 5 +++-- ops/write.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Streamer.js b/Streamer.js index 2092131..f3ad0f9 100644 --- a/Streamer.js +++ b/Streamer.js @@ -5,15 +5,16 @@ const { Duplex, Readable } = require('stream') const { Buffer } = require('buffer') class Streamer { - constructor(socket_uuid, node_uuid, length = 4096, position = 0) { + constructor(socket_uuid, node_uuid, length = 4096, position = 0, descriptor = undefined) { this.socket_uuid = socket_uuid this.node_uuid = node_uuid this.length = length this.position = position + this.descriptor = descriptor } write(buffer) { - const write_stream = WebSocketStream(`ws://localhost:5746/?socket_uuid=${this.socket_uuid}&node_uuid=${this.node_uuid}&length=${this.length}&position=${this.position}&writing_file=true`, { + const write_stream = WebSocketStream(`ws://localhost:5746/?socket_uuid=${this.socket_uuid}&node_uuid=${this.node_uuid}&length=${this.length}&position=${this.position}&writing_file=true&descriptor=${this.descriptor}`, { perMessageDeflate: false, binary: true, }) diff --git a/ops/write.js b/ops/write.js index 0605ada..18de17f 100644 --- a/ops/write.js +++ b/ops/write.js @@ -6,10 +6,10 @@ const Streamer = require('../Streamer') module.exports = exports = async function (path, fd, buffer, length, position, cb) { try { - const { socket_uuid, node_uuid } = await connector.simple_request('stream.getfd', { descriptor: fd }) - console.log({socket_uuid, node_uuid}) + const { socket_uuid, node_uuid, descriptor } = await connector.simple_request('stream.getfd', { descriptor: fd }) + console.log({socket_uuid, node_uuid, descriptor}) - const streamer = new Streamer(socket_uuid, node_uuid, length, position) + const streamer = new Streamer(socket_uuid, node_uuid, length, position, descriptor) streamer.write(buffer).then(() => { return process.nextTick(cb, length) })