Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set flag for writing file #69

Open
Fndroid opened this issue Mar 25, 2019 · 0 comments
Open

Set flag for writing file #69

Fndroid opened this issue Mar 25, 2019 · 0 comments

Comments

@Fndroid
Copy link

Fndroid commented Mar 25, 2019

Here is the situation.

let tempPath = '' // C:\Users\abc\AppData\Local\Temp
let tempFilePath = path.join(tempPath, 'geoip.tar.gz')
let destPath = '' // C:\Users\abc\.config\clash
got
  .stream("xxx/GeoLite2-Country.tar.gz")
  .pipe(fs.createWriteStream(tempFilePath))
  .on("finish", async () => {
    let decRes = await decompress(tempFilePath, path.join(destPath, 'Country.mmdb'));
  });

I tried set decompress dest path to my destPath directly, and it threw an unknown error. It seems that destPath is hidden on Windows (.config directory).

So I dig up from fs library, a solution is set flag to 'r+'

On Windows, opening an existing hidden file using the 'w' flag (either through fs.open() or fs.writeFile() or fsPromises.open()) will fail with EPERM. Existing hidden files can be opened for writing with the 'r+' flag.

......
  .on("finish", async () => {
    let decRes = await decompress(tempFilePath, path.join(tempPath, 'decompress_output'));
  });
  if (decRes.length === 1) {
    fs.writeFileSync(path.join(this.clashPath, 'Country.mmdb'), decRes[0].data, {flag: "r+"})
  }

So, is there a way to get rid of this extra decompress_output directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant