Search code examples
javascriptnode.jsfilesystemsfuse

Cannot open MS word, PDF on Fuse based file system


I am trying to implement Fuse Based file system using Node.js on Mac. I am using fuse-native (https://github.com/fuse-friends/fuse-native) for mounting a file system.

I have a directory on my local file system that I want to mirror with the mounted file system. So if I save file on mounted file system, it should save to the mirrored directory and if I download file in mirrored directory, I should be able to open it on mounted directory.

I have implemented all the basic fuse callbacks like read, readdir, write, getattr, chmod, chown, mknod, mkdir, rmdir

So far, I am able to create, update, delete, save text file to mounted file system. When I try to open any MS word, pdf or pages file from the mounted file system (that's present on mirrored directory), it gives me

Word found unreadable content in file.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes.

and when I click recover, it is successfully able to recover it.

I am not sure what's going on but not able to open the word file.

My read function looks like (I am reading and opening from mirrored directory): fs is the node file system

fs.read(fd, buf, 0, buf.length, null, (err, bytesRead, buffer) => {
      if (err) {
        Logger.info(err.message);
        return cb(Fuse.ENOENT);
      }
      const part = buffer.slice(position, position + bytesRead);
      part.copy(buffer);
      return cb(bytesRead);
    });

and open:

const open = (path: string, flags: number, cb: Function) => {
  // Logger.info('In Open');
  try {
    const fd = fs.openSync(
      `/Users/xyz/Desktop/Fuse${path}`,
      toFlag(flags)
    );
    return cb(0, fd);
  } catch (err) {
    Logger.info(err.message);
    return cb(Fuse.ENOENT);
  }
};

Any help would be appreciated. Thank you!


Solution

  • This was fixed by changing the read function. Read was wrong.

    try {
          const bytesRead = fs.readSync(fd, buf, 0, length, position);
          return cb(bytesRead);
        } catch (error) {
          Logger.info(error.message);
          return cb(Fuse.ENOENT);
        }