Set flag for writing file
- Dominant language
- JavaScript
- Stars
- 419
- Forks
- 55
- PR merge metrics
- No merged PRs in 30d
Description
Here is the situation.
```javascript
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.
```javascript
......
.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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the shown decompress call and the fs.writeFileSync workaround, then inspect how extraction writes to a Windows hidden destination. Reproduce the EPERM or unknown error with the provided archive and destination setup; done means the archive can write Country.mmdb directly without an extra decompress_output directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100