JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q38278F
  • License MIT

a zip archiver for xlsx, support zip64.

Package Exports

  • xlsx-zip
  • xlsx-zip/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xlsx-zip) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Xlsx-Zip

NPM

Xlsx-Zip is a library that adapts for Office Xlsx Zip format. You can use it to compress xlsx's metadata, but can't extract.

this library is inspired by node-compress-commons and node-zip.

Feature

  • Zip format compatible with Office Xlsx
  • Support zip64
  • Support both stream and buffer output

Why this project

Microsoft Office Xlsx Zip doesn't adapt standard Zip(PK-ZIP) format completely, which doesn't support ZIP64 Central Directory. So most Zip library can't generate a standard Office Xlsx file. The library is created to generate it perfectly.

Reference

Install

npm i xlsx-zip

Usage

Buffer

const { XlsxZip } = require('xlsx-zip');
const fs = require('fs');

async function main() {
  // don't set `stream` parameter
  const xlsxZip = new XlsxZip();

  const dirPath = 'directory/path';
  // add by directory
  await xlsxZip.addDirectory(null, dirPath);
  // add by Buffer
  await xlsxZip.add('entry/path1', Buffer.from('entry'));
  // add by Buffer list
  await xlsxZip.add('entry/path1', [Buffer.from('entry')]);
  // add by file stream
  const rs = fs.createReadStream('file/path');
  await xlsxZip.add('entry/path2', rs);

  const buf = await xlsxZip.finish();

  fs.writeFileSync('./output.xlsx', buf);
}

Stream

const { XlsxZip } = require('xlsx-zip');
const fs = require('fs');

async function main() {
  const stream = fs.createWriteStream('./output.xlsx');
  const xlsxZip = new XlsxZip({ stream });

  stream.on('close', () => {
    console.log('done');
  });

  const dirPath = 'directory/path';
  // add by directory
  await xlsxZip.addDirectory(null, dirPath);
  // add by Buffer
  await xlsxZip.add('entry/path1', Buffer.from('entry'));
  // add by Buffer list
  await xlsxZip.add('entry/path1', [Buffer.from('entry')]);
  // add by file stream
  const rs = fs.createReadStream('file/path');
  await xlsxZip.add('entry/path2', rs);

  await xlsxZip.finish();
}

RegExp

you can filter some path you don't want to add into ZIP stream with regExp parameter

const { XlsxZip } = require('xlsx-zip');
const fs = require('fs');

async function main() {
  const xlsxZip = new XlsxZip({
    regExp: '.DS_Store'
  });
  // or
  const xlsxZip = new XlsxZip({
    regExp: new RegExp('.DS_Store')
  });

  const dirPath = 'directory/path';
  // add by directory
  await xlsxZip.addDirectory(null, dirPath);

  const buf = await xlsxZip.finish();

  fs.writeFileSync('./output.xlsx', buf);
}