jszip icon indicating copy to clipboard operation
jszip copied to clipboard

Please add es6 module support

Open softboy99 opened this issue 4 years ago • 2 comments

Please add es6 module support

softboy99 avatar Oct 15 '20 01:10 softboy99

See #349. If you want tree shaking, check out fflate, which is faster, supports ES modules, and smaller.

101arrowz avatar Nov 05 '20 23:11 101arrowz

fflate works.

An example of how to use it in a web browser, which is not in their readme (@101arrowz):

import { unzipSync, strFromU8 } from 'fflate'

/**
 * Reads XLSX file in a browser.
 * @param  {File} file - A `File` object being uploaded in the browser.
 * @return {Promise} Resolves to an object holding XLSX file entries.
 */
export default function unpackXlsxFile(file) {
	return file.arrayBuffer().then((fileBuffer) => {
		const archive = new Uint8Array(fileBuffer)
		const contents = unzipSync(archive)
		return getContents(contents)
		// return new Promise((resolve, reject) => {
		// 	unzip(archive, (error, contents) => {
		// 		if (error) {
		// 			return reject(error)
		// 		}
		// 		return resolve(getContents(contents))
		// 	})
		// })
	})
}

function getContents(contents) {
	const unzippedFiles = []
	for (const key of Object.keys(contents)) {
		unzippedFiles[key] = strFromU8(contents[key])
	}
	return unzippedFiles
}

catamphetamine avatar Sep 14 '22 06:09 catamphetamine