observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
961 stars 83 forks source link

Add support for ZIP file attachments. #222

Closed mbostock closed 3 years ago

mbostock commented 3 years ago

Adds fileAttachment.zip which returns a promise to a ZipArchive. The ZipArchive exposes an archive.fileNames() method which returns the array of file names, and an archive.file(name) method which returns a FileAttachment-like object. So, to load a CSV file in a ZIP file, you can now say:

archive = FileAttachment("ACS_14_5YR_B01003.zip").zip()
data = archive.file("ACS_14_5YR_B01003_with_ann.csv").csv({typed: true})

As with XLSX #215, I’ve decided not to expose JSZip as a recommended library, and instead wrap it with a more minimal abstraction that feels more Observable-ish.

Screen Shot 2021-06-01 at 6 47 28 PM
mbostock commented 3 years ago

I assume for archives with directories, the filenames array will contain values like "dir/file.csv"? and only contain files and not "dir/"?

Good catch. It did include directories, but now I’ve filtered them out.