refactor(lana): use URI-safe file access - #952
Conversation
| const buf = Buffer.alloc(4096); | ||
| const bytesRead = readSync(fd, buf, 0, 4096, 0); | ||
| const text = buf.toString('utf8', 0, bytesRead); | ||
| const text = (await readFile(uri)).slice(0, 4096); |
There was a problem hiding this comment.
This reads the whole file. we used to only read the first 4096 bytes to handle 100MB + logs.
We did this to support the code lenses on very large files vscode only returns document if it is less than 50MB I think (from memory) which is why we did this.
We could use the below which will give us the Uint8Array and avoid decoding the full file
const text = new TextDecoder().decode(bytes.subarray(0, 4096));
There was a problem hiding this comment.
Addressed as far as the current URI-safe APIs allow in 957277e. Detection now reads through workspace.fs and decodes only the first 4 KB from the returned byte array, preserving arbitrary URI providers and avoiding Node modules. workspace.fs still returns the complete byte array, so a true bounded provider read needs a future Services or filesystem-provider API; I am leaving this thread open for that remaining limitation.
957277e to
4c271ca
Compare
PR overview
Stack 2 of 4. Depends on #951. Makes log and workspace handling URI-native so Lana can operate against local and virtual filesystems.
Changes made
Type of change
Related issues
related W-23939830
Validation