mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Improved PKPass.pack to reduce the amount of iterations that gets done
This commit is contained in:
@@ -102,18 +102,16 @@ export default class PKPass extends Bundle {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static pack(...passes: PKPass[]): Bundle {
|
static pack(...passes: PKPass[]): Bundle {
|
||||||
if (!passes.every((pass) => pass instanceof PKPass)) {
|
|
||||||
throw new Error(Messages.PACK.INVALID);
|
|
||||||
}
|
|
||||||
|
|
||||||
const buffers = passes.map((pass) => pass.getAsBuffer());
|
|
||||||
|
|
||||||
const [bundle, freezeBundle] = Bundle.freezable(
|
const [bundle, freezeBundle] = Bundle.freezable(
|
||||||
"application/vnd.apple.pkpasses",
|
"application/vnd.apple.pkpasses",
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let i = 0; i < buffers.length; i++) {
|
for (let i = 0, pass: PKPass; (pass = passes[i]); i++) {
|
||||||
bundle.addBuffer(`packed-pass-${i + 1}.pkpass`, buffers[i]);
|
if (!(pass instanceof PKPass)) {
|
||||||
|
throw new Error(Messages.PACK.INVALID);
|
||||||
|
}
|
||||||
|
|
||||||
|
bundle.addBuffer(`packed-pass-${i + 1}.pkpass`, pass.getAsBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
freezeBundle();
|
freezeBundle();
|
||||||
|
|||||||
Reference in New Issue
Block a user