Add flush handler and make Streamer.write await close

master
Garrett Mills 3 years ago
parent e38cb3ed30
commit ecc35f94f6
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -21,6 +21,12 @@ class Streamer {
const combined_stream = CombinedStream.create()
combined_stream.append(buffer.toString('base64'))
combined_stream.pipe(write_stream)
return new Promise(res => {
write_stream.socket.on('close', () => {
res()
})
})
}
stream() {

@ -17,6 +17,7 @@ const ops = {
unlink: require('./ops/unlink'),
rename: require('./ops/rename'),
write: require('./ops/write'),
flush: require('./ops/flush'),
}
;(async () => {

@ -0,0 +1,20 @@
const Fuse = require('fuse-native')
const Errors = require('../../shared/Errors')
const Message = require('../../shared/Message')
const connector = require('../connector')
module.exports = exports = function (path, fd, cb) {
console.log('[FLUSH]')
connector.send(
Message.route('fs.flush')
.data({ path, descriptor: fd })
.expect_response(msg => {
if ( msg.error() ) {
return Errors.toCallback(cb, msg.error())
}
console.log('[/FLUSH]')
return process.nextTick(cb, 0)
})
)
}

@ -4,6 +4,7 @@ const Message = require('../../shared/Message')
const connector = require('../connector')
module.exports = exports = function (path, fd, cb) {
console.log('[RELEASE]')
connector.send(
Message.route('fs.release')
.data({ path, descriptor: fd })
@ -12,6 +13,7 @@ module.exports = exports = function (path, fd, cb) {
return Errors.toCallback(cb, msg.error())
}
console.log('[/RELEASE]')
return process.nextTick(cb, 0)
})
)

@ -10,9 +10,9 @@ module.exports = exports = async function (path, fd, buffer, length, position, c
console.log({socket_uuid, node_uuid})
const streamer = new Streamer(socket_uuid, node_uuid, length, position)
streamer.write(buffer)
return process.nextTick(cb, length)
streamer.write(buffer).then(() => {
return process.nextTick(cb, length)
})
} catch (e) {
console.error(e)
}

Loading…
Cancel
Save