mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c307ad7686
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: https://github.com/nodejs/node/pull/50960 Refs: https://github.com/nodejs/single-executable/issues/68 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
32 lines
895 B
JavaScript
32 lines
895 B
JavaScript
'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);
|
|
}
|