How to use the fs-xattr.getAsync function in fs-xattr

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 / src / fruitmix / file / my_xstat.js View on Github external
const readXstatAsync = async target => {
  let attr, dirty, stats = await fs.lstatAsync(target)
  if(!stats.isFile() && !stats.isDirectory())
    throw Object.assign(new Error('not a directory or file'), { code: 'ENOTDIRORFILE' })

  try{
    attr = await JSON.parse(xattr.getAsync(target, FRUITMIX))

    if(attr.hasOwnProperty('owner')) {
      validateOldFormat()

      dirty = true
      delete attr.owner
      if(attr.writelist === null) delete attr.writelist
      if(attr.readlist === null) delete attr.readlist
      if(stats.isFile())
        attr.magic = attr.magic ? parseMagic(attr.magic) : fileMagic(attr.magic)
    } else
      validateNewFormat(attr)

    // drop hash if outdated
    if(stats.isFile() && attr.htime && attr.htime !== stats.mtime) {
      dirty = true
github wisnuc / appifi / test / fruitmix / unit / lib / ref.js View on Github external
it('should calculate hash if file has no xattr', async () => {
      try {
        await xattr.getAsync(filepath, 'user.fruitmix')
      } catch(e) {
        expect(e.code).to.be.equal('ENODATA')
      }
      
      let hash = await repo.storeFileAsync(filepath)
      expect(hash).to.equal(sha256)
    })
github wisnuc / appifi / src / fruitmix / cluster / lib / filemap.js View on Github external
throw new E.EINVAL()
  }
  if(segments[start] === 1){
    console.log('该段以上传', segments)
    throw new E.EEXIST()
  }
  
  let segmentSize = attr.segmentsize
  let segmentLength = segments.length > start + 1 ? segmentSize : (attr.size - start * segmentSize)
  let position = attr.segmentsize * start

  let updater = new SegmentUpdater(fpath, req, position, segmentHash, segmentLength)

  await updater.startAsync()
  try{
    attr = JSON.parse(await xattr.getAsync(fpath, FILEMAP))
    attr.segments[start] = 1
    await xattr.setAsync(fpath, FILEMAP, JSON.stringify(attr))
    if(attr.segments.includes(0)) return false
    let fname = await autoRenameAsync(attr.userUUID, attr.dirUUID, attr.name)
    console.log('----------------' + fname)
    await moveFileMapAsync(attr.userUUID, attr.dirUUID, fname, fpath, attr.sha256)
    return true
  }catch(e){
    console.log(e)
    throw e
  }
}

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