From 03759b84cfc6fdee8dca9192edc8ac96ee2c2165 Mon Sep 17 00:00:00 2001 From: Victor Soares Date: Fri, 7 Apr 2023 23:33:47 -0300 Subject: [PATCH] :adhesive_bandage: fix: buffer compress not work --- package.json | 2 +- src/compress.ts | 3 ++- src/index.ts | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c4b4e13..27ced54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "compress-pdf", - "version": "0.3.0", + "version": "0.3.1", "templateVersion": "1.3.0", "description": "An compress pdf library using ghostscript", "main": "dist/index.js", diff --git a/src/compress.ts b/src/compress.ts index 21f9151..42a8264 100644 --- a/src/compress.ts +++ b/src/compress.ts @@ -33,6 +33,7 @@ async function compress(file: string | Buffer, options?: Options) { command = `${gsModule} -q -dNOPAUSE -dBATCH -dSAFER -dSimulateOverprint=true -sDEVICE=pdfwrite -dCompatibilityLevel=${compatibilityLevel} -dPDFSETTINGS=/${resolution} -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dColorImageDownsampleType=/Bicubic -dColorImageResolution=${imageQuality} -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=${imageQuality} -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=${imageQuality} -sOutputFile=${output} ${file}`; } else { tempFile = path.resolve(os.tmpdir(), (Date.now() * 2).toString()); + await fs.promises.writeFile(tempFile, file); command = `${gsModule} -q -dNOPAUSE -dBATCH -dSAFER -dSimulateOverprint=true -sDEVICE=pdfwrite -dCompatibilityLevel=${compatibilityLevel} -dPDFSETTINGS=/${resolution} -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dColorImageDownsampleType=/Bicubic -dColorImageResolution=${imageQuality} -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=${imageQuality} -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=${imageQuality} -sOutputFile=${output} ${tempFile}`; @@ -44,7 +45,7 @@ async function compress(file: string | Buffer, options?: Options) { const readFile = await fs.promises.readFile(output); - await fs.unlinkSync(readFile); + await fs.unlinkSync(output); return readFile; } diff --git a/src/index.ts b/src/index.ts index 196e7ef..19d5e75 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,9 @@ export { default as getGSModulePath } from './get-gs-module-path'; export { default as getBinPath } from './get-bin-path'; export { default as compress } from './compress'; - -export * from './fetch-binaries'; +export { + default as fetchBinaries, + GS_VERSION, + RELEASE_URL, +} from './fetch-binaries'; export * from './types';