Add flush handler and make Streamer.write await close
This commit is contained in:
parent
e38cb3ed30
commit
ecc35f94f6
@ -21,6 +21,12 @@ class Streamer {
|
|||||||
const combined_stream = CombinedStream.create()
|
const combined_stream = CombinedStream.create()
|
||||||
combined_stream.append(buffer.toString('base64'))
|
combined_stream.append(buffer.toString('base64'))
|
||||||
combined_stream.pipe(write_stream)
|
combined_stream.pipe(write_stream)
|
||||||
|
|
||||||
|
return new Promise(res => {
|
||||||
|
write_stream.socket.on('close', () => {
|
||||||
|
res()
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stream() {
|
stream() {
|
||||||
|
1
index.js
1
index.js
@ -17,6 +17,7 @@ const ops = {
|
|||||||
unlink: require('./ops/unlink'),
|
unlink: require('./ops/unlink'),
|
||||||
rename: require('./ops/rename'),
|
rename: require('./ops/rename'),
|
||||||
write: require('./ops/write'),
|
write: require('./ops/write'),
|
||||||
|
flush: require('./ops/flush'),
|
||||||
}
|
}
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
|
20
ops/flush.js
Normal file
20
ops/flush.js
Normal file
@ -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')
|
const connector = require('../connector')
|
||||||
|
|
||||||
module.exports = exports = function (path, fd, cb) {
|
module.exports = exports = function (path, fd, cb) {
|
||||||
|
console.log('[RELEASE]')
|
||||||
connector.send(
|
connector.send(
|
||||||
Message.route('fs.release')
|
Message.route('fs.release')
|
||||||
.data({ path, descriptor: fd })
|
.data({ path, descriptor: fd })
|
||||||
@ -12,6 +13,7 @@ module.exports = exports = function (path, fd, cb) {
|
|||||||
return Errors.toCallback(cb, msg.error())
|
return Errors.toCallback(cb, msg.error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[/RELEASE]')
|
||||||
return process.nextTick(cb, 0)
|
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})
|
console.log({socket_uuid, node_uuid})
|
||||||
|
|
||||||
const streamer = new Streamer(socket_uuid, node_uuid, length, position)
|
const streamer = new Streamer(socket_uuid, node_uuid, length, position)
|
||||||
streamer.write(buffer)
|
streamer.write(buffer).then(() => {
|
||||||
|
|
||||||
return process.nextTick(cb, length)
|
return process.nextTick(cb, length)
|
||||||
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user