Fix file write streaming logic
This commit is contained in:
parent
d1e9d38f53
commit
203dda2abb
@ -5,15 +5,16 @@ const { Duplex, Readable } = require('stream')
|
|||||||
const { Buffer } = require('buffer')
|
const { Buffer } = require('buffer')
|
||||||
|
|
||||||
class Streamer {
|
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.socket_uuid = socket_uuid
|
||||||
this.node_uuid = node_uuid
|
this.node_uuid = node_uuid
|
||||||
this.length = length
|
this.length = length
|
||||||
this.position = position
|
this.position = position
|
||||||
|
this.descriptor = descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
write(buffer) {
|
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,
|
perMessageDeflate: false,
|
||||||
binary: true,
|
binary: true,
|
||||||
})
|
})
|
||||||
|
@ -6,10 +6,10 @@ const Streamer = require('../Streamer')
|
|||||||
|
|
||||||
module.exports = exports = async function (path, fd, buffer, length, position, cb) {
|
module.exports = exports = async function (path, fd, buffer, length, position, cb) {
|
||||||
try {
|
try {
|
||||||
const { socket_uuid, node_uuid } = await connector.simple_request('stream.getfd', { descriptor: fd })
|
const { socket_uuid, node_uuid, descriptor } = await connector.simple_request('stream.getfd', { descriptor: fd })
|
||||||
console.log({socket_uuid, node_uuid})
|
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(() => {
|
streamer.write(buffer).then(() => {
|
||||||
return process.nextTick(cb, length)
|
return process.nextTick(cb, length)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user