diff --git a/index.js b/index.js index 0616a90..576f41a 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,10 @@ const ops = { rename: require('./ops/rename'), write: require('./ops/write'), flush: require('./ops/flush'), + getxattr: require('./ops/getxattr'), + setxattr: require('./ops/setxattr'), + removexattr: require('./ops/removexattr'), + listxattr: require('./ops/listxattr'), } ;(async () => { diff --git a/ops/getxattr.js b/ops/getxattr.js new file mode 100644 index 0000000..067c936 --- /dev/null +++ b/ops/getxattr.js @@ -0,0 +1,25 @@ +const Fuse = require('fuse-native') +const Errors = require('../../shared/Errors') +const Message = require('../../shared/Message') +const connector = require('../connector') +const { Buffer } = require('buffer') + +module.exports = exports = function (path, name, position, cb) { + connector.send( + Message.route('fs.xattr.get') + .data({ path, name }) + .expect_response(msg => { + if ( msg.error() ) { + return Errors.toCallback(cb, msg.error()) + } + + const { value } = msg.data() + + if ( !value ) { + return process.nextTick(cb, 0, null) + } + + return process.nextTick(cb, 0, Buffer.from(value, 'base64')) + }) + ) +} diff --git a/ops/listxattr.js b/ops/listxattr.js new file mode 100644 index 0000000..2ebc082 --- /dev/null +++ b/ops/listxattr.js @@ -0,0 +1,19 @@ +const Fuse = require('fuse-native') +const Errors = require('../../shared/Errors') +const Message = require('../../shared/Message') +const connector = require('../connector') + +module.exports = exports = function (path, name, cb) { + connector.send( + Message.route('fs.xattr.list') + .data({ path, name }) + .expect_response(msg => { + if ( msg.error() ) { + return Errors.toCallback(cb, msg.error()) + } + + const { names } = msg.data() + return process.nextTick(cb, 0, names) + }) + ) +} diff --git a/ops/removexattr.js b/ops/removexattr.js new file mode 100644 index 0000000..e1c0818 --- /dev/null +++ b/ops/removexattr.js @@ -0,0 +1,18 @@ +const Fuse = require('fuse-native') +const Errors = require('../../shared/Errors') +const Message = require('../../shared/Message') +const connector = require('../connector') + +module.exports = exports = function (path, name, cb) { + connector.send( + Message.route('fs.xattr.remove') + .data({ path, name }) + .expect_response(msg => { + if ( msg.error() ) { + return Errors.toCallback(cb, msg.error()) + } + + return process.nextTick(cb, 0) + }) + ) +} diff --git a/ops/setxattr.js b/ops/setxattr.js new file mode 100644 index 0000000..a4acd74 --- /dev/null +++ b/ops/setxattr.js @@ -0,0 +1,22 @@ +const Fuse = require('fuse-native') +const Errors = require('../../shared/Errors') +const Message = require('../../shared/Message') +const connector = require('../connector') + +module.exports = exports = function (path, name, value, position, flags, cb) { + connector.send( + Message.route('fs.xattr.set') + .data({ + path, + name, + value: value.toString('base64'), // value is a Buffer of binary data + }) + .expect_response(msg => { + if ( msg.error() ) { + return Errors.toCallback(cb, msg.error()) + } + + return process.nextTick(cb, 0) + }) + ) +}