diff --git a/src/asar_archive.js b/src/asar_archive.js index 05060f4..40914ac 100644 --- a/src/asar_archive.js +++ b/src/asar_archive.js @@ -81,8 +81,8 @@ class AsarArchive { const node = this.getNode(filePath) if (!node) return null - if (node.files) - return null + if (node.files) // dir + return { path: filePath, unpacked: node.unpacked } if (node.link) return this.getFileInfo(node.link) const info = { path: filePath, size: node.size } @@ -96,6 +96,8 @@ class AsarArchive { readFile(info) { if (info.unpacked) throw new Error('Should not use readFile for unpacked path') + if (typeof info.size != 'number') + throw new Error('readFile only works on file') const buffer = Buffer.alloc(info.size) const fd = fs.openSync(process.execPath, 'r') try { @@ -109,6 +111,8 @@ class AsarArchive { } copyFileOut(info) { + if (typeof info.size != 'number') + throw new Error('copyFileOut only works on file') if (this.tmpFiles[info.path]) return this.tmpFiles[info.path] if (info.unpacked) diff --git a/test/asar_fs_realpath_dir/dir/file b/test/asar_fs_realpath_dir/dir/file new file mode 100644 index 0000000..e69de29 diff --git a/test/asar_fs_realpath_dir/index.js b/test/asar_fs_realpath_dir/index.js new file mode 100644 index 0000000..9f8e63a --- /dev/null +++ b/test/asar_fs_realpath_dir/index.js @@ -0,0 +1,5 @@ +const fs = require('node:fs') +const path = require('node:path') + +process.stdout.write(fs.realpathSync(path.join(__dirname, 'dir'))) +process.exit(0) diff --git a/test/main.js b/test/main.js index 21ad1bb..25b438c 100755 --- a/test/main.js +++ b/test/main.js @@ -110,22 +110,29 @@ describe('node', function() { assert.equal(result.stdout.toString().trim(), p) }) - it('start with asar with async fs', async () => { + it('start with asar with offset', async () => { + const result = await packageAndRun('fs_async', changeOffset) + assert.equal(result.status, 0) + assert.ok(result.stdout.toString().includes('fs.readFile(__filename')) + }) + + it('async fs works on asar', async () => { const result = await packageAndRun('fs_async') assert.equal(result.status, 0) assert.ok(result.stdout.toString().includes('fs.readFile(__filename')) }) - it('start with asar with promise fs', async () => { + it('promise fs works on asar', async () => { const result = await packageAndRun('fs_promise') assert.equal(result.status, 0) assert.ok(result.stdout.toString().includes('fs.readFile(__filename')) }) - it('start with asar with offset', async () => { - const result = await packageAndRun('fs_async', changeOffset) + it('fs.realpathSync works on dir in asar', async () => { + const result = await packageAndRun('fs_realpath_dir') + console.log(result.stderr.toString()) assert.equal(result.status, 0) - assert.ok(result.stdout.toString().includes('fs.readFile(__filename')) + assert.ok(result.stdout.toString().endsWith(path.join('asar', 'dir'))); }) it('Promise can resolve', async () => {