Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add es6 module support #717

Open
softboy99 opened this issue Oct 15, 2020 · 2 comments
Open

Please add es6 module support #717

softboy99 opened this issue Oct 15, 2020 · 2 comments

Comments

@softboy99
Copy link

Please add es6 module support

@101arrowz
Copy link

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

@catamphetamine
Copy link

catamphetamine commented Sep 14, 2022

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants