Skip to content

Commit d8f633e

Browse files
committed
maker-appimage: Use ES buffer APIs in joinFiles.
Re-write `joinFiles` to not to rely on Node's `Buffer` API, allowing to use this function outside Node env as well if needed (making code more future-proof if anything).
1 parent 2ddd786 commit d8f633e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

makers/appimage/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
348348
setChecksum(runtime, await readFile(outFile)) :
349349
runtime
350350
)*/
351-
.then(runtime => joinFiles(Buffer.from(runtime),outFile))
351+
.then(runtime => joinFiles(runtime,outFile))
352352
.then(buffer => writeFile(outFile, buffer))
353353
.then(() => chmod(outFile, 0o755))
354354
// Finally, return a path to maker artifacts

makers/appimage/src/utils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,25 @@ export function getSquashFsVer() {
256256
/**
257257
* Concatenates files and/or buffers into a new buffer.
258258
*/
259-
export async function joinFiles(...filesAndBuffers:(string|Buffer)[]) {
259+
export async function joinFiles(...filesAndBuffers:(string|ArrayBufferLike|Uint8Array)[]) {
260260
const {readFile} = await import("fs/promises");
261-
const bufferArray: Promise<Buffer>[] = [];
261+
const bufferArray: Promise<Uint8Array>[] = [];
262262
for(const path of filesAndBuffers)
263-
if(Buffer.isBuffer(path))
264-
bufferArray.push(Promise.resolve(path));
265-
else if (existsSync(path))
263+
if(path instanceof <Uint8ArrayConstructor>Object.getPrototypeOf(Uint8Array))
264+
bufferArray.push(Promise.resolve(new Uint8Array(path.buffer)));
265+
else if(path instanceof ArrayBuffer || path instanceof SharedArrayBuffer)
266+
bufferArray.push(Promise.resolve(new Uint8Array(path)));
267+
else if(existsSync(path))
266268
bufferArray.push(readFile(path));
267269
else
268270
throw new Error(`Unable to concat '${path}': Invalid path.`);
269-
return Promise.all(bufferArray).then(array => Buffer.concat(array))
271+
return Promise.all(bufferArray)
272+
.then(array => new Uint8Array(
273+
new Array<number>().concat(
274+
...array.map(v => [...v])
275+
)
276+
)
277+
)
270278
}
271279

272280
/**

0 commit comments

Comments
 (0)