|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | + |
| 6 | +const fs = require('fs'); |
| 7 | +const promiseFs = require('fs').promises; |
| 8 | +const path = require('path'); |
| 9 | +const tmpdir = require('../common/tmpdir'); |
| 10 | + |
| 11 | +tmpdir.refresh(); |
| 12 | + |
| 13 | +let testIndex = 0; |
| 14 | + |
| 15 | +function getFilename() { |
| 16 | + const filename = path.join(tmpdir.path, `test-file-${++testIndex}`); |
| 17 | + fs.writeFileSync(filename, 'test'); |
| 18 | + return filename; |
| 19 | +} |
| 20 | + |
| 21 | +function verifyStats(bigintStats, numStats) { |
| 22 | + const keys = [ |
| 23 | + 'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'size', |
| 24 | + ]; |
| 25 | + if (!common.isWindows) { |
| 26 | + keys.push('blocks', 'blksize', 'ino'); |
| 27 | + } |
| 28 | + for (const key of keys) { |
| 29 | + const nVal = numStats[key]; |
| 30 | + const bVal = bigintStats[key]; |
| 31 | + assert.strictEqual( |
| 32 | + bigintStats[key], BigInt(numStats[key]), |
| 33 | + `bigintStats.${key}: ${bVal} is not equal to numStats.${key}: ${nVal}` |
| 34 | + ); |
| 35 | + assert.ok( |
| 36 | + Number.isSafeInteger(nVal), |
| 37 | + `numStats.${key}: ${nVal} is not a safe integer` |
| 38 | + ); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +{ |
| 43 | + const filename = getFilename(); |
| 44 | + const bigintStats = fs.statSync(filename, { bigint: true }); |
| 45 | + const numStats = fs.statSync(filename); |
| 46 | + verifyStats(bigintStats, numStats); |
| 47 | +} |
| 48 | + |
| 49 | +{ |
| 50 | + const filename = __filename; |
| 51 | + const bigintStats = fs.statSync(filename, { bigint: true }); |
| 52 | + const numStats = fs.statSync(filename); |
| 53 | + verifyStats(bigintStats, numStats); |
| 54 | +} |
| 55 | + |
| 56 | +{ |
| 57 | + const filename = __dirname; |
| 58 | + const bigintStats = fs.statSync(filename, { bigint: true }); |
| 59 | + const numStats = fs.statSync(filename); |
| 60 | + verifyStats(bigintStats, numStats); |
| 61 | +} |
| 62 | + |
| 63 | +{ |
| 64 | + const filename = getFilename(); |
| 65 | + const fd = fs.openSync(filename, 'r'); |
| 66 | + const bigintStats = fs.fstatSync(fd, { bigint: true }); |
| 67 | + const numStats = fs.fstatSync(fd); |
| 68 | + verifyStats(bigintStats, numStats); |
| 69 | + fs.closeSync(fd); |
| 70 | +} |
| 71 | + |
| 72 | +{ |
| 73 | + const filename = getFilename(); |
| 74 | + fs.stat(filename, { bigint: true }, (err, bigintStats) => { |
| 75 | + fs.stat(filename, (err, numStats) => { |
| 76 | + verifyStats(bigintStats, numStats); |
| 77 | + }); |
| 78 | + }); |
| 79 | +} |
| 80 | + |
| 81 | +{ |
| 82 | + const filename = getFilename(); |
| 83 | + const fd = fs.openSync(filename, 'r'); |
| 84 | + fs.fstat(fd, { bigint: true }, (err, bigintStats) => { |
| 85 | + fs.fstat(fd, (err, numStats) => { |
| 86 | + verifyStats(bigintStats, numStats); |
| 87 | + fs.closeSync(fd); |
| 88 | + }); |
| 89 | + }); |
| 90 | +} |
| 91 | + |
| 92 | +(async function() { |
| 93 | + const filename = getFilename(); |
| 94 | + const bigintStats = await promiseFs.stat(filename, { bigint: true }); |
| 95 | + const numStats = await promiseFs.stat(filename); |
| 96 | + verifyStats(bigintStats, numStats); |
| 97 | +})(); |
| 98 | + |
| 99 | +(async function() { |
| 100 | + const filename = getFilename(); |
| 101 | + const handle = await promiseFs.open(filename, 'r'); |
| 102 | + const bigintStats = await handle.stat({ bigint: true }); |
| 103 | + const numStats = await handle.stat(); |
| 104 | + verifyStats(bigintStats, numStats); |
| 105 | + await handle.close(); |
| 106 | +})(); |
0 commit comments