-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds support for `sea.getRawAsset()` which is similar to `sea.getAsset()` but returns the raw asset in an array buffer without copying. Users should avoid writing to the returned array buffer. If the injected section is not marked as writable or not aligned, writing to the raw asset is likely to result in a crash. PR-URL: #50960 Refs: nodejs/single-executable#68 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
- Loading branch information
1 parent
cea5295
commit e8d9065
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,5 +71,6 @@ function getAssetAsBlob(key, options) { | |
module.exports = { | ||
isSea, | ||
getAsset, | ||
getRawAsset, | ||
getAssetAsBlob, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const { isSea, getAsset, getRawAsset } = require('node:sea'); | ||
const { readFileSync } = require('fs'); | ||
const assert = require('assert'); | ||
|
||
assert(isSea()); | ||
|
||
{ | ||
assert.throws(() => getRawAsset('nonexistent'), { | ||
code: 'ERR_SINGLE_EXECUTABLE_APPLICATION_ASSET_NOT_FOUND' | ||
}); | ||
assert.throws(() => getRawAsset(null), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
assert.throws(() => getRawAsset(1), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
} | ||
|
||
{ | ||
// Check that the asset embedded is the same as the original. | ||
const assetOnDisk = readFileSync(process.env.__TEST_PERSON_JPG); | ||
const assetCopy = getAsset('person.jpg') | ||
const assetCopyBuffer = Buffer.from(assetCopy); | ||
assert.deepStrictEqual(assetCopyBuffer, assetOnDisk); | ||
|
||
// Check that the copied asset is the same as the raw one. | ||
const rawAsset = getRawAsset('person.jpg'); | ||
assert.deepStrictEqual(rawAsset, assetCopy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
test/sequential/test-single-executable-application-assets-raw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const { | ||
injectAndCodeSign, | ||
skipIfSingleExecutableIsNotSupported, | ||
} = require('../common/sea'); | ||
|
||
skipIfSingleExecutableIsNotSupported(); | ||
|
||
// This tests the snapshot support in single executable applications. | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
const { copyFileSync, writeFileSync, existsSync } = require('fs'); | ||
const { | ||
spawnSyncAndExitWithoutError, | ||
} = require('../common/child_process'); | ||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
tmpdir.refresh(); | ||
if (!tmpdir.hasEnoughSpace(120 * 1024 * 1024)) { | ||
common.skip('Not enough disk space'); | ||
} | ||
|
||
const configFile = tmpdir.resolve('sea-config.json'); | ||
const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); | ||
const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); | ||
|
||
{ | ||
tmpdir.refresh(); | ||
copyFileSync(fixtures.path('sea', 'get-asset-raw.js'), tmpdir.resolve('sea.js')); | ||
copyFileSync(fixtures.path('person.jpg'), tmpdir.resolve('person.jpg')); | ||
writeFileSync(configFile, ` | ||
{ | ||
"main": "sea.js", | ||
"output": "sea-prep.blob", | ||
"assets": { | ||
"person.jpg": "person.jpg" | ||
} | ||
} | ||
`, 'utf8'); | ||
|
||
spawnSyncAndExitWithoutError( | ||
process.execPath, | ||
['--experimental-sea-config', 'sea-config.json'], | ||
{ | ||
env: { | ||
NODE_DEBUG_NATIVE: 'SEA', | ||
...process.env, | ||
}, | ||
cwd: tmpdir.path | ||
}, | ||
{}); | ||
|
||
assert(existsSync(seaPrepBlob)); | ||
|
||
copyFileSync(process.execPath, outputFile); | ||
injectAndCodeSign(outputFile, seaPrepBlob); | ||
|
||
spawnSyncAndExitWithoutError( | ||
outputFile, | ||
{ | ||
env: { | ||
...process.env, | ||
NODE_DEBUG_NATIVE: 'SEA', | ||
__TEST_PERSON_JPG: fixtures.path('person.jpg'), | ||
} | ||
}, | ||
{ } | ||
); | ||
} |