fix: return numeric blksize and blocks from asar fs.stat (#50876)

fix: return numeric `blksize` and `blocks` from asar `fs.stat`

Previously, `fs.stat` on files inside `.asar` archives returned
`undefined` for `blksize` and `blocks`, violating the Node.js API
contract where these fields must be `number | bigint`.

Use `4096` for `blksize` (matching the convention used by `memfs` and
the proposed `node:vfs` module in nodejs/node#61478) and compute
`blocks` as `ceil(size / 512)` (standard 512-byte block units).

Fixes #42686

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
This commit is contained in:
trop[bot]
2026-04-10 12:15:26 +02:00
committed by GitHub
parent 45232e2ce7
commit 8720df9baa
2 changed files with 10 additions and 2 deletions

View File

@@ -135,10 +135,10 @@ const asarStatsToFsStats = function (stats: NodeJS.AsarFileStat) {
uid,
gid,
0, // rdev
undefined, // blksize
4096, // blksize
++nextInode, // ino
stats.size,
undefined, // blocks,
Math.ceil(stats.size / 512), // blocks (512-byte units)
fakeTime.getTime(), // atim_msec
fakeTime.getTime(), // mtim_msec
fakeTime.getTime(), // ctim_msec

View File

@@ -458,6 +458,14 @@ describe('asar package', function () {
expect(stats.size).to.equal(0);
});
itremote('returns stat properties with types matching a real file', function () {
const asarStats = fs.lstatSync(path.join(asarDir, 'a.asar', 'file1'));
const realStats = fs.lstatSync(path.join(fixtures, 'test.asar', 'a.asar'));
for (const key of Object.keys(realStats) as (keyof typeof realStats)[]) {
expect(typeof asarStats[key]).to.equal(typeof realStats[key], `typeof stats.${key}`);
}
});
itremote('returns information of root with stats as bigint', function () {
const p = path.join(asarDir, 'a.asar');
const stats = fs.lstatSync(p, { bigint: false });