From db7f2c5ede385db7c29b7d17cf7fa605b44e9a9e Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Tue, 24 Sep 2024 09:04:36 +0200 Subject: [PATCH] docs: explain how to execute binary from snapshot --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 3c50aced..88b9c19b 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,34 @@ const child = spawn(process.execPath, [process.argv[1]], { More info [here](https://github.com/yao-pkg/pkg/pull/90) +### Error: Cannot execute binaray from snapshot + +Binaries must be extracted from snapshot in order to be executed. In order to do this you can use this approach: + +```js +const cp = require('child_process'); +const fs = require('fs'); +const { pipeline } = require('stream/promises'); + +let ffmpeg = require('@ffmpeg-installer/ffmpeg').path; + +const loadPlugin = async () => { + if (process.pkg) { + // copy ffmpeg to the current directory + const file = fs.createWriteStream('ffmpeg'); + await pipeline(fs.createReadStream(ffmpeg), file); + + fs.chmodSync('ffmpeg', 0o755); + console.log('ffmpeg copied to the current directory'); + ffmpeg = './ffmpeg'; + } + + cp.execSync(ffmpeg); +}; + +loadPlugin(); +``` + ### Error: ENOENT: no such file or directory, uv_chdir This error can be caused by deleting the directory the application is