Skip to content

Commit

Permalink
Merge pull request #27 from victorsoares96/fix/compress-buffer-not-work
Browse files Browse the repository at this point in the history
🩹 fix: buffer compress not work
  • Loading branch information
victorsoares96 authored Apr 8, 2023
2 parents d22beef + 03759b8 commit 71a8c9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 71a8c9f

Please sign in to comment.