Fix file write streaming logic

This commit is contained in:
Garrett Mills 2020-11-29 11:54:11 -06:00
parent d1e9d38f53
commit 203dda2abb
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 6 additions and 5 deletions

View File

@ -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,
})

View File

@ -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)
})