Skip to content

Commit

Permalink
fix attachments mixin (#2121)
Browse files Browse the repository at this point in the history
* fix attachments mixin

* add change set
  • Loading branch information
jeetiss authored Dec 27, 2022
1 parent 0d9c891 commit 8536f10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-squids-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/pdfkit': patch
---

fix `attachments` mixin
14 changes: 6 additions & 8 deletions packages/pdfkit/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ const babelConfig = () => ({
});

const getExternal = ({ browser }) => [
...Object.keys(pkg.dependencies)
.filter(dep => 'crypto-js' !== dep)
.filter(
dep =>
!browser ||
!['vite-compatible-readable-stream', 'browserify-zlib'].includes(dep)
),
...Object.keys(pkg.dependencies).filter(
dep =>
!browser ||
!['vite-compatible-readable-stream', 'browserify-zlib'].includes(dep)
),
/\/node_modules\/pako\//,
'crypto-js/md5',
/crypto-js/,
'@babel/runtime/helpers/inheritsLoose',
'@babel/runtime/helpers/assertThisInitialized',
'@babel/runtime/helpers/createForOfIteratorHelperLoose',
Expand Down
24 changes: 10 additions & 14 deletions packages/pdfkit/src/mixins/attachments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import CryptoJS from 'crypto-js/md5';
import * as CryptoJS from 'crypto-js/core';
import MD5 from 'crypto-js/md5';

export default {
/**
Expand Down Expand Up @@ -65,9 +66,7 @@ export default {
}

// add checksum and size information
const checksum = CryptoJS.MD5(
CryptoJS.lib.WordArray.create(new Uint8Array(data))
);
const checksum = MD5(CryptoJS.lib.WordArray.create(new Uint8Array(data)));
refBody.Params.CheckSum = new String(checksum);
refBody.Params.Size = data.byteLength;

Expand Down Expand Up @@ -107,14 +106,11 @@ export default {

/** check two embedded file metadata objects for equality */
function isEqual(a, b) {
if (
a.Subtype !== b.Subtype ||
a.Params.CheckSum.toString() !== b.Params.CheckSum.toString() ||
a.Params.Size !== b.Params.Size ||
a.Params.CreationDate !== b.Params.CreationDate ||
a.Params.ModDate !== b.Params.ModDate
) {
return false;
}
return true;
return (
a.Subtype === b.Subtype &&
a.Params.CheckSum.toString() === b.Params.CheckSum.toString() &&
a.Params.Size === b.Params.Size &&
a.Params.CreationDate === b.Params.CreationDate &&
a.Params.ModDate === b.Params.ModDate
);
}

0 comments on commit 8536f10

Please sign in to comment.