From 2271e426e2f1adbbaea32ba496bc11e35debef49 Mon Sep 17 00:00:00 2001 From: calebboyd Date: Tue, 31 Jul 2018 14:46:10 -0500 Subject: [PATCH] fix: encoding options closes #510 --- package.json | 2 +- src/steps/shim-fs.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index eb81e9e..c7db8e1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "nexe", "description": "Create a single executable out of your Node.js application", "license": "MIT", - "version": "2.0.0-rc.33", + "version": "2.0.0-rc.34", "contributors": [ "Craig Condon (http://crcn.io)", "Jared Allard ", diff --git a/src/steps/shim-fs.ts b/src/steps/shim-fs.ts index 2d41101..1b25d60 100644 --- a/src/steps/shim-fs.ts +++ b/src/steps/shim-fs.ts @@ -80,6 +80,10 @@ function makeLong(filepath: string) { return (path as any)._makeLong && (path as any)._makeLong(filepath) } +function fileOpts(options: any) { + return !options ? {} : isString(options) ? { encoding: options } : options +} + let setupManifest = () => { Object.keys(manifest).forEach(filepath => { const entry = manifest[filepath] @@ -176,7 +180,7 @@ const nfs: any = { } const [offset, length] = entry const resourceOffset = resourceStart + offset - const encoding = isString(options) ? options : null + const encoding = fileOpts(options).encoding callback = typeof options === 'function' ? options : callback fs.open(process.execPath, 'r', function(err: Error, fd: number) { @@ -208,7 +212,7 @@ const nfs: any = { } const [offset, length] = entry const resourceOffset = resourceStart + offset - const opts = !options ? {} : isString(options) ? { encoding: options } : options + const opts = fileOpts(options) return fs.createReadStream( process.execPath, @@ -227,7 +231,7 @@ const nfs: any = { } const [offset, length] = entry const resourceOffset = resourceStart + offset - const encoding = isString(options) ? options : null + const encoding = fileOpts(options).encoding const fd = fs.openSync(process.execPath, 'r') const result = Buffer.alloc(length) fs.readSync(fd, result, 0, length, resourceOffset)