Comments (5)
By the way, I expected that it will not support ADS (Alternate Data Streams) too, but it works fine.
import fs from "node:fs/promises";
await fs.writeFile("ads.txt", `data:ads.txt`);
await fs.writeFile("ads.txt:metadata", `metadata:ads.txt`); // Alternate Data Stream
console.log((await fs.readFile("ads.txt")).toString());
console.log((await fs.readFile("ads.txt:metadata")).toString());
console.log((await fs.stat("ads.txt:metadata")).size);
await fs.unlink("ads.txt");
data:ads.txt
metadata:ads.txt
16
Anyway, it makes sense to add a test for it too in fs.test.ts
, just in case.
from bun.
It's strange, but adding \\?\
does not help. While it should help.
https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#skip-normalization
Unless the path starts exactly with
\\?\
(note the use of the canonical backslash), it is normalized.Why would you want to skip normalization? There are three major reasons:
- To get access to paths that are normally unavailable but are legal. A file or directory called
hidden.
, for example, is impossible to access in any other way.- To improve performance by skipping normalization if you've already normalized.
- To skip the
MAX_PATH
check for path length to allow for paths that are greater than 259 characters.
import fs from "node:fs/promises";
import path from "node:path";
for (const filename of [" spaces.txt ", ".dots.txt."]) {
// const prefixed_filename = path.toNamespacedPath(path.resolve(filename)); // still does not work #8247
const prefixed_filename = "\\\\?\\" + path.resolve(filename);
console.log(prefixed_filename);
try {
await fs.writeFile(prefixed_filename, `data:"${filename}"`);
} catch (e) { console.error(e); }
try {
console.log((await fs.readFile(prefixed_filename)).toString());
} catch (e) { console.error(e); }
try {
console.log((await fs.stat(prefixed_filename)).size);
} catch (e) { console.error(e); }
try {
await fs.unlink(filename);
continue;
} catch (e) { console.error(e); }
try {
const newName = filename.replaceAll(/^[ .]+|[ .]+$/g, "");
await fs.rename(prefixed_filename, newName);
} catch (e) { console.error(e); }
}
More over, in this case fs.writeFile
fails too.
In this case the prefix works:
from bun.
Well, this works in Bun:
import fs from "node:fs/promises";
import path from "node:path";
for (const filename of [" spaces.txt ", ".dots.txt."]) {
try {
await fs.writeFile(filename, `data:"${filename}"`);
} catch (e) { console.error(e); }
const prefixed_filename = "\\\\?\\" + path.resolve(filename);
console.log(prefixed_filename);
try {
console.log((await fs.readFile(prefixed_filename)).toString());
} catch (e) { console.error(e); }
try {
console.log((await fs.stat(prefixed_filename)).size);
} catch (e) { console.error(e); }
try {
await fs.unlink(filename);
continue;
} catch (e) { console.error(e); }
try {
const newName = filename.replaceAll(/^[ .]+|[ .]+$/g, "");
await fs.rename(prefixed_filename, newName);
} catch (e) { console.error(e); }
}
from bun.
fs.writeFile
works without "\\\\?\\"
, but with the prefix it stops to work.
Other functions begin to work after adding of this prefix.
All examples above works in Node.js (regardless of the presence of the prefix).
from bun.
const prefixed_filename = "\\\\?\\" + path.resolve(filename);
is a simplified version of toNamespacedPath
i think once the path pr merges it might be worthwhile to use that api internally for all the fs stuff on windows. it probably should replace PosixToWinNormalizer
, which is only really hitting SOME of the cases you present, and is why this only half works.
from bun.
Related Issues (20)
- `bunx --bun astro dev` does not reload configuration
- TLS handshake timeout
- [BUN API] Unable to use fetch with UNIX Socket
- Building a dependency causes `Attempted to assign to a readonly property` HOT 2
- Built-in Tasks Scheduler supports cron expressions
- add possiblity to export dependencies to package-lock.json
- Improve DX of patching when updating packages HOT 1
- Segmentation fault? from WASM? HOT 1
- Silent crash when streaming from stdin
- Crash during a long running script
- --- Bun is auto-restarting due to crash [time: 1724066411841] --- HOT 1
- Bun installation the dreaded "command not found"
- `bun build --compile`: `Bun.resolve(..., import.meta.url)` resolves relative to `cwd` HOT 5
- add `once` to HTMLRewriter
- Bun v1.1.16 repl crash on macos Sonoma w/ M3 HOT 2
- add option to keep node: specifier after bundling
- `bun:sqlite` in strict mode to accept parameters with and without prefix
- `require` defined in global scope, `globalThis.require` undefined HOT 11
- node:net destroy dont call end
- TypeError: module.register is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bun.