From 55a5592ab6fda4f3c769d6173f69ad9101e6550e Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Mon, 25 Jun 2018 09:23:04 -0400 Subject: [PATCH] Add optional type param to export sprite API. --- src/virtual-machine.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index b0571e52c..7218d4432 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -281,7 +281,19 @@ class VirtualMachine extends EventEmitter { } } - exportSprite (targetId) { + /** + * Exports a sprite in the sprite3 format. + * @param {string} targetId ID of the target to export + * @param {string=} optZipType Optional type that the resulting + * zip should be outputted in. Options are: base64, binarystring, + * array, uint8array, arraybuffer, blob, or nodebuffer. Defaults to + * blob if argument not provided. + * See https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html#type-option + * for more information about these options. + * @return {object} A generated zip of the sprite and its assets in the format + * specified by optZipType or blob by default. + */ + exportSprite (targetId, optZipType) { const soundDescs = serializeSounds(this.runtime, targetId); const costumeDescs = serializeCostumes(this.runtime, targetId); const spriteJson = JSON.stringify(sb3.serialize(this.runtime, targetId)); @@ -291,7 +303,7 @@ class VirtualMachine extends EventEmitter { this._addFileDescsToZip(soundDescs.concat(costumeDescs), zip); return zip.generateAsync({ - type: 'blob', + type: typeof optZipType === 'string' ? optZipType : 'blob', compression: 'DEFLATE', compressionOptions: { level: 6