How to use fs-xattr - 10 common examples

To help you get started, we’ve selected a few fs-xattr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wisnuc / appifi / test / fruitmix / file / xstat.js View on Github external
it('should force xstat of directory with existing (different) uuid', async () => {

    let xstat

    await xattr.setAsync(tmpdir, 'user.fruitmix', JSON.stringify({ uuid: uuidArr[0] }))

    // xstat = await readXstatAsync(tmpdir)
    // expect(xstat.uuid).to.equal(uuidArr[0])

    xstat = await forceDriveXstatAsync(tmpdir, uuidArr[2])
    expect(xstat).to.deep.equal(pre)
  })
})
github wisnuc / appifi / test / fruitmix / file / probe.js View on Github external
let xstats = []
  await Promise.delay(100)
  for (let prop in tree) {
    if (tree.hasOwnProperty(prop)) {

      let npath = path.join(tmpdir, prop)
      // console.log(npath)      
      if (tree[prop].type === 'directory') {
        await mkdirpAsync(npath)
        xattr.setAsync(npath, 'user.fruitmix', JSON.stringify({
          uuid: tree[prop].uuid 
        }))
      }
      else {
        await fs.writeFileAsync(npath, '\n')
        xattr.setAsync(npath, 'user.fruitmix', JSON.stringify({
          uuid: tree[prop].uuid,
          magic: 0
        }))
      } 

      xstats.push(await readXstatAsync(npath))
    }
  }

  xstats.sort((a, b) => a.name.localeCompare(b.name))

  let stats = await fs.lstatAsync(dir)
  let mtime = stats.mtime.getTime()

  return { mtime, xstats }
}
github wisnuc / appifi / test / unit / tasks / xcopy-single.js View on Github external
xc.once('stopped', () => {
      // assert state
      expect(xc.root.state.constructor.name).to.equal('Finished')
      // assert file system and vfs
      let attr = JSON.parse(xattr.getSync(path.join(tmptest, 'drives', rootUUID, 'b', 'c'), 'user.fruitmix'))
      let dirBC = vfs.findDirByName('c', 'b')
      expect(dirBC.uuid).to.equal(attr.uuid)
      done()
    })
  }))
github wisnuc / appifi / test / unit / vfs / forest.js View on Github external
expect(root.uuid).to.equal(rootUUID)
      expect(root.name).to.equal(rootUUID)
      expect(root.mtime < 0).to.be.true
      expect(root.state instanceof Directory.Init).to.be.true

      // root is in roots
      expect(forest.roots.get(rootUUID)).to.equal(root)

      // root is indexed
      expect(forest.uuidMap.get(rootUUID)).to.equal(root)

      // root is in initDirs
      expect(forest.initDirs.has(rootUUID)).to.be.true

      // root directory has been stamped
      let fattr = xattr.getSync(path.join(tmptest, 'drives', rootUUID), 'user.fruitmix')
      let attr = JSON.parse(fattr) 
      expect(attr).to.deep.equal({ uuid: rootUUID })

      // scheduled
      expect(forest.dirReadScheduled).to.be.true

      // run scheduler
      setImmediate(() => { 

        // root moved to readingDirs
        expect(root.state instanceof Directory.Reading).to.be.true
        expect(forest.initDirs.has(rootUUID)).to.be.false 
        expect(forest.readingDirs.has(rootUUID)).to.be.true

        // until read done
        forest.on('DirReadDone', () => {
github wisnuc / appifi / assets.js View on Github external
// test xxhash
  const XXHASH = require('xxhash')
  console.log('test xxhash: ' + XXHASH.hash(Buffer.from('hello'), 1234))
}

if (xattrBase64) {

  mkdirp.sync(dir)

  let decode = Buffer.from(xattrBase64.toString(), 'base64')
  fs.writeFileSync(path.join(dir, 'xattr.node'), decode)

  // test xattr
  const XATTR = require('fs-xattr')
  XATTR.setSync(dir, 'user.foo', 'bar')
  console.log('test xattr: ' + XATTR.getSync(dir, 'user.foo'))
  XATTR.removeSync(dir, 'user.foo')
}

function loadFont (base64, name) {

  if (base64) 
    return Buffer.from(base64, 'base64')
  else
    return fs.readFileSync('./public/stylesheets/Roboto-' + name + '-webfont.woff')
}

robotoThin = loadFont(robotoThinBase64, 'Thin')
robotoLight = loadFont(robotoLightBase64, 'Light')
robotoRegular = loadFont(robotoRegularBase64, 'Regular')
robotoMedium = loadFont(robotoMediumBase64, 'Medium')
robotoBold = loadFont(robotoBoldBase64, 'Bold')
github wisnuc / appifi / src / fruitmix / VFS.js View on Github external
createRoot(uuid) {
    let dirPath = path.join(this.driveDir, uuid)
    let stats, attr = { uuid }
    try {
      mkdirp.sync(dirPath)
      stats = fs.lstatSync(dirPath)
      // this is tricky but works
      xattr.setSync(dirPath, 'user.fruitmix', JSON.stringify(attr))
    } catch (e) {
      console.log(e)
      return
    }
    let name = path.basename(dirPath)
    let xstat = {
      uuid: attr.uuid,
      type: 'directory',
      name,
      mtime: stats.mtime.getTime()
    }
    return this.forest.createRoot(uuid, xstat)
  }
github wisnuc / appifi / assets.js View on Github external
// test xxhash
  const XXHASH = require('xxhash')
  console.log('test xxhash: ' + XXHASH.hash(Buffer.from('hello'), 1234))
}

if (xattrBase64) {

  mkdirp.sync(dir)

  let decode = Buffer.from(xattrBase64.toString(), 'base64')
  fs.writeFileSync(path.join(dir, 'xattr.node'), decode)

  // test xattr
  const XATTR = require('fs-xattr')
  XATTR.setSync(dir, 'user.foo', 'bar')
  console.log('test xattr: ' + XATTR.getSync(dir, 'user.foo'))
  XATTR.removeSync(dir, 'user.foo')
}

function loadFont (base64, name) {

  if (base64) 
    return Buffer.from(base64, 'base64')
  else
    return fs.readFileSync('./public/stylesheets/Roboto-' + name + '-webfont.woff')
}

robotoThin = loadFont(robotoThinBase64, 'Thin')
robotoLight = loadFont(robotoLightBase64, 'Light')
robotoRegular = loadFont(robotoRegularBase64, 'Regular')
robotoMedium = loadFont(robotoMediumBase64, 'Medium')
github viddo / atom-textual-velocity / lib / service-consumers / NVTags.js View on Github external
write(path, str, callback) {
        var tags = str
          .trim()
          .split(" ")
          .reduce((memo, val) => {
            if (memo.indexOf(val) === -1) {
              memo.push(val);
            }
            return memo;
          }, []);

        if (tags.length && tags[0] !== "") {
          var plistBuf = bplist.create([tags]);
          xattr.set(path, XATTR_KEY, plistBuf, callback);
        } else {
          xattr.remove(path, XATTR_KEY, callback);
        }

        var now = new Date();
        fs.utimesSync(path, now, now); // update last access/update times
      }
    });
github viddo / atom-textual-velocity / lib / service-consumers / NVTags.js View on Github external
write(path, str, callback) {
        var tags = str
          .trim()
          .split(" ")
          .reduce((memo, val) => {
            if (memo.indexOf(val) === -1) {
              memo.push(val);
            }
            return memo;
          }, []);

        if (tags.length && tags[0] !== "") {
          var plistBuf = bplist.create([tags]);
          xattr.set(path, XATTR_KEY, plistBuf, callback);
        } else {
          xattr.remove(path, XATTR_KEY, callback);
        }

        var now = new Date();
        fs.utimesSync(path, now, now); // update last access/update times
      }
    });
github wisnuc / appifi / assets.js View on Github external
const XXHASH = require('xxhash')
  console.log('test xxhash: ' + XXHASH.hash(Buffer.from('hello'), 1234))
}

if (xattrBase64) {

  mkdirp.sync(dir)

  let decode = Buffer.from(xattrBase64.toString(), 'base64')
  fs.writeFileSync(path.join(dir, 'xattr.node'), decode)

  // test xattr
  const XATTR = require('fs-xattr')
  XATTR.setSync(dir, 'user.foo', 'bar')
  console.log('test xattr: ' + XATTR.getSync(dir, 'user.foo'))
  XATTR.removeSync(dir, 'user.foo')
}

function loadFont (base64, name) {

  if (base64) 
    return Buffer.from(base64, 'base64')
  else
    return fs.readFileSync('./public/stylesheets/Roboto-' + name + '-webfont.woff')
}

robotoThin = loadFont(robotoThinBase64, 'Thin')
robotoLight = loadFont(robotoLightBase64, 'Light')
robotoRegular = loadFont(robotoRegularBase64, 'Regular')
robotoMedium = loadFont(robotoMediumBase64, 'Medium')
robotoBold = loadFont(robotoBoldBase64, 'Bold')
robotoBlack = loadFont(robotoBlackBase64, 'Black')

fs-xattr

Node.js module for manipulating extended attributes.

MIT
Latest version published 4 years ago

Package Health Score

50 / 100
Full package analysis

Similar packages