@zip.js/zip.js
Advanced tools
Comparing version 2.0.12 to 2.1.0
@@ -12,3 +12,3 @@ { | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
@@ -15,0 +15,0 @@ }, |
@@ -103,5 +103,5 @@ declare module "zip.js" { | ||
signature: Uint8Array; | ||
extraField: Map<number, Uint8Array>; | ||
extraField?: Map<number, Uint8Array>; | ||
rawExtraField: Uint8Array; | ||
getData(writer: Writer, options?: GetDataOptions): Promise<any>; | ||
getData?(writer: Writer, options?: GetDataOptions): Promise<any>; | ||
} | ||
@@ -118,3 +118,3 @@ | ||
constructor(writer: Writer, options?: ZipWriterOptions); | ||
public add(name: string, reader: Reader, options?: AddDataOptions): Promise<void>; | ||
public add(name: string, reader: Reader, options?: AddDataOptions): Promise<Entry>; | ||
public close(comment?: Uint8Array): Promise<any>; | ||
@@ -165,2 +165,4 @@ } | ||
getData(writer: Writer, options?: GetDataOptions): Promise<any>; | ||
replaceBlob(blob: Blob): void; | ||
replaceText(text: String): void; | ||
} | ||
@@ -167,0 +169,0 @@ |
46
index.js
@@ -31,43 +31,3 @@ /* | ||
import { | ||
fs, | ||
configure, | ||
initShimAsyncCodec, | ||
ZipReader, | ||
ZipWriter, | ||
Reader, | ||
Writer, | ||
TextReader, | ||
TextWriter, | ||
Data64URIReader, | ||
Data64URIWriter, | ||
BlobReader, | ||
BlobWriter, | ||
HttpReader, | ||
HttpRangeReader, | ||
Uint8ArrayWriter, | ||
Uint8ArrayReader, | ||
ERR_HTTP_RANGE, | ||
ERR_BAD_FORMAT, | ||
ERR_EOCDR_NOT_FOUND, | ||
ERR_EOCDR_ZIP64_NOT_FOUND, | ||
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, | ||
ERR_CENTRAL_DIRECTORY_NOT_FOUND, | ||
ERR_LOCAL_FILE_HEADER_NOT_FOUND, | ||
ERR_EXTRAFIELD_ZIP64_NOT_FOUND, | ||
ERR_ENCRYPTED, | ||
ERR_UNSUPPORTED_ENCRYPTION, | ||
ERR_UNSUPPORTED_COMPRESSION, | ||
ERR_INVALID_SIGNATURE, | ||
ERR_INVALID_PASSORD, | ||
ERR_DUPLICATED_NAME, | ||
ERR_INVALID_COMMENT, | ||
ERR_INVALID_ENTRY_NAME, | ||
ERR_INVALID_ENTRY_COMMENT, | ||
ERR_INVALID_VERSION, | ||
ERR_INVALID_DATE, | ||
ERR_INVALID_EXTRAFIELD_TYPE, | ||
ERR_INVALID_EXTRAFIELD_DATA | ||
} from "./lib/zip-fs.js"; | ||
import getMimeType from "./lib/util/mime-type.js"; | ||
import getMimeType from "./lib/core/util/mime-type.js"; | ||
@@ -78,3 +38,2 @@ export { | ||
initShimAsyncCodec, | ||
getMimeType, | ||
ZipReader, | ||
@@ -115,2 +74,3 @@ ZipWriter, | ||
ERR_INVALID_EXTRAFIELD_DATA | ||
}; | ||
} from "./lib/zip-fs.js"; | ||
export { getMimeType }; |
@@ -32,4 +32,4 @@ | ||
import "./z-worker-core.js"; | ||
import { default as initShimAsyncCodec } from "./util/stream-codec-shim.js"; | ||
import "./core/z-worker-core.js"; | ||
import { default as initShimAsyncCodec } from "./core/util/stream-codec-shim.js"; | ||
@@ -36,0 +36,0 @@ self.initCodec = () => { |
@@ -31,5 +31,5 @@ /* | ||
import "./z-worker-core.js"; | ||
import Deflate from "./codecs/deflate.js"; | ||
import Inflate from "./codecs/inflate.js"; | ||
import "./core/z-worker-core.js"; | ||
import Deflate from "./core/codecs/deflate.js"; | ||
import Inflate from "./core/codecs/inflate.js"; | ||
@@ -36,0 +36,0 @@ self.initCodec = () => { |
@@ -31,484 +31,2 @@ /* | ||
import { | ||
configure, | ||
getMimeType, | ||
initShimAsyncCodec, | ||
ZipReader, | ||
ZipWriter, | ||
Reader, | ||
Writer, | ||
TextReader, | ||
TextWriter, | ||
Data64URIReader, | ||
Data64URIWriter, | ||
BlobReader, | ||
BlobWriter, | ||
HttpReader, | ||
HttpRangeReader, | ||
Uint8ArrayWriter, | ||
Uint8ArrayReader, | ||
ERR_HTTP_RANGE, | ||
ERR_BAD_FORMAT, | ||
ERR_EOCDR_NOT_FOUND, | ||
ERR_EOCDR_ZIP64_NOT_FOUND, | ||
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, | ||
ERR_CENTRAL_DIRECTORY_NOT_FOUND, | ||
ERR_LOCAL_FILE_HEADER_NOT_FOUND, | ||
ERR_EXTRAFIELD_ZIP64_NOT_FOUND, | ||
ERR_ENCRYPTED, | ||
ERR_UNSUPPORTED_ENCRYPTION, | ||
ERR_UNSUPPORTED_COMPRESSION, | ||
ERR_INVALID_SIGNATURE, | ||
ERR_INVALID_PASSORD, | ||
ERR_DUPLICATED_NAME, | ||
ERR_INVALID_COMMENT, | ||
ERR_INVALID_ENTRY_NAME, | ||
ERR_INVALID_ENTRY_COMMENT, | ||
ERR_INVALID_VERSION, | ||
ERR_INVALID_DATE, | ||
ERR_INVALID_EXTRAFIELD_TYPE, | ||
ERR_INVALID_EXTRAFIELD_DATA | ||
} from "./zip.js"; | ||
const CHUNK_SIZE = 512 * 1024; | ||
class ZipEntry { | ||
constructor(fs, name, params, parent) { | ||
if (fs.root && parent && parent.getChildByName(name)) { | ||
throw new Error("Entry filename already exists"); | ||
} | ||
if (!params) { | ||
params = {}; | ||
} | ||
this.fs = fs; | ||
this.name = name; | ||
this.data = params.data; | ||
this.id = fs.entries.length; | ||
this.parent = parent; | ||
this.children = []; | ||
this.uncompressedSize = 0; | ||
fs.entries.push(this); | ||
if (parent) { | ||
this.parent.children.push(this); | ||
} | ||
} | ||
moveTo(target) { | ||
if (target.directory) { | ||
if (!target.isDescendantOf(this)) { | ||
if (this != target) { | ||
if (target.getChildByName(this.name)) { | ||
throw new Error("Entry filename already exists"); | ||
} | ||
detach(this); | ||
this.parent = target; | ||
target.children.push(this); | ||
} | ||
} else { | ||
throw new Error("Entry is a ancestor of target entry"); | ||
} | ||
} else { | ||
throw new Error("Target entry is not a directory"); | ||
} | ||
} | ||
getFullname() { | ||
let fullname = this.name, entry = this.parent; | ||
while (entry) { | ||
fullname = (entry.name ? entry.name + "/" : "") + fullname; | ||
entry = entry.parent; | ||
} | ||
return fullname; | ||
} | ||
isDescendantOf(ancestor) { | ||
let entry = this.parent; | ||
while (entry && entry.id != ancestor.id) { | ||
entry = entry.parent; | ||
} | ||
return Boolean(entry); | ||
} | ||
} | ||
class ZipFileEntry extends ZipEntry { | ||
constructor(fs, name, params, parent) { | ||
super(fs, name, params, parent); | ||
this.Reader = params.Reader; | ||
this.Writer = params.Writer; | ||
if (params.getData) { | ||
this.getData = params.getData; | ||
} | ||
} | ||
async getData(writer, options = {}) { | ||
if (!writer || (writer.constructor == this.Writer && this.data)) { | ||
return this.data; | ||
} else { | ||
if (!this.reader) { | ||
this.reader = new this.Reader(this.data); | ||
} | ||
await this.reader.init(); | ||
await writer.init(); | ||
this.uncompressedSize = this.reader.size; | ||
return bufferedCopy(this.reader, writer, options); | ||
} | ||
} | ||
getText(encoding, options) { | ||
return this.getData(new TextWriter(encoding), options); | ||
} | ||
getBlob(mimeType, options) { | ||
return this.getData(new BlobWriter(mimeType), options); | ||
} | ||
getData64URI(mimeType, options) { | ||
return this.getData(new Data64URIWriter(mimeType), options); | ||
} | ||
} | ||
class ZipDirectoryEntry extends ZipEntry { | ||
constructor(fs, name, params, parent) { | ||
super(fs, name, params, parent); | ||
this.directory = true; | ||
} | ||
addDirectory(name) { | ||
return addChild(this, name, null, true); | ||
} | ||
addText(name, text) { | ||
return addChild(this, name, { | ||
data: text, | ||
Reader: TextReader, | ||
Writer: TextWriter | ||
}); | ||
} | ||
addBlob(name, blob) { | ||
return addChild(this, name, { | ||
data: blob, | ||
Reader: BlobReader, | ||
Writer: BlobWriter | ||
}); | ||
} | ||
addData64URI(name, dataURI) { | ||
return addChild(this, name, { | ||
data: dataURI, | ||
Reader: Data64URIReader, | ||
Writer: Data64URIWriter | ||
}); | ||
} | ||
addHttpContent(name, url, options = {}) { | ||
return addChild(this, name, { | ||
data: url, | ||
Reader: options.useRangeHeader ? HttpRangeReader : HttpReader | ||
}); | ||
} | ||
addFileEntry(fileEntry) { | ||
addFileEntry(this, fileEntry); | ||
} | ||
async addData(name, params) { | ||
return addChild(this, name, params); | ||
} | ||
async importBlob(blob, options = {}) { | ||
await this.importZip(new BlobReader(blob), options); | ||
} | ||
async importData64URI(dataURI, options = {}) { | ||
await this.importZip(new Data64URIReader(dataURI), options); | ||
} | ||
async importHttpContent(URL, options = {}) { | ||
await this.importZip(options.useRangeHeader ? new HttpRangeReader(URL) : new HttpReader(URL), options); | ||
} | ||
async exportBlob(options = {}) { | ||
return this.exportZip(new BlobWriter("application/zip"), options); | ||
} | ||
async exportData64URI(options = {}) { | ||
return this.exportZip(new Data64URIWriter("application/zip"), options); | ||
} | ||
async importZip(reader, options) { | ||
await reader.init(); | ||
const zipReader = new ZipReader(reader, options); | ||
const entries = await zipReader.getEntries(); | ||
let currentIndex = 0; | ||
const totalSize = getTotalSize(entries, "compressedSize"); | ||
entries.forEach(entry => { | ||
let parent = this, path = entry.filename.split("/"), name = path.pop(); | ||
path.forEach(pathPart => parent = parent.getChildByName(pathPart) || new ZipDirectoryEntry(this.fs, pathPart, null, parent)); | ||
if (!entry.directory) { | ||
let currentIndexEntry = currentIndex; | ||
addChild(parent, name, { | ||
data: entry, | ||
Reader: getZipBlobReader(Object.assign({}, { | ||
onprogress: indexProgress => { | ||
if (options.onprogress) { | ||
options.onprogress(currentIndexEntry + indexProgress, totalSize); | ||
} | ||
} | ||
})) | ||
}); | ||
currentIndex += entry.compressedSize; | ||
} | ||
}); | ||
} | ||
async exportZip(writer, options) { | ||
await initReaders(this); | ||
const zipWriter = new ZipWriter(writer, options); | ||
await exportZip(zipWriter, this, getTotalSize([this], "uncompressedSize"), options); | ||
await zipWriter.close(); | ||
return writer.getData(); | ||
} | ||
getChildByName(name) { | ||
for (let childIndex = 0; childIndex < this.children.length; childIndex++) { | ||
const child = this.children[childIndex]; | ||
if (child.name == name) | ||
return child; | ||
} | ||
} | ||
} | ||
class FS { | ||
constructor() { | ||
resetFS(this); | ||
} | ||
remove(entry) { | ||
detach(entry); | ||
this.entries[entry.id] = null; | ||
} | ||
find(fullname) { | ||
const path = fullname.split("/"); | ||
let node = this.root; | ||
for (let index = 0; node && index < path.length; index++) { | ||
node = node.getChildByName(path[index]); | ||
} | ||
return node; | ||
} | ||
getById(id) { | ||
return this.entries[id]; | ||
} | ||
async importBlob(blob) { | ||
resetFS(this); | ||
await this.root.importBlob(blob); | ||
} | ||
async importData64URI(dataURI) { | ||
resetFS(this); | ||
await this.root.importData64URI(dataURI); | ||
} | ||
async importHttpContent(url, options) { | ||
this.entries = []; | ||
this.root = new ZipDirectoryEntry(this); | ||
await this.root.importHttpContent(url, options); | ||
} | ||
async exportBlob(options) { | ||
return this.root.exportBlob(options); | ||
} | ||
async exportData64URI(options) { | ||
return this.root.exportData64URI(options); | ||
} | ||
} | ||
const fs = { FS, ZipDirectoryEntry, ZipFileEntry }; | ||
export { | ||
fs, | ||
configure, | ||
initShimAsyncCodec, | ||
getMimeType, | ||
ZipReader, | ||
ZipWriter, | ||
Reader, | ||
Writer, | ||
TextReader, | ||
TextWriter, | ||
Data64URIReader, | ||
Data64URIWriter, | ||
BlobReader, | ||
BlobWriter, | ||
HttpReader, | ||
HttpRangeReader, | ||
Uint8ArrayWriter, | ||
Uint8ArrayReader, | ||
ERR_HTTP_RANGE, | ||
ERR_BAD_FORMAT, | ||
ERR_EOCDR_NOT_FOUND, | ||
ERR_EOCDR_ZIP64_NOT_FOUND, | ||
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, | ||
ERR_CENTRAL_DIRECTORY_NOT_FOUND, | ||
ERR_LOCAL_FILE_HEADER_NOT_FOUND, | ||
ERR_EXTRAFIELD_ZIP64_NOT_FOUND, | ||
ERR_ENCRYPTED, | ||
ERR_UNSUPPORTED_ENCRYPTION, | ||
ERR_UNSUPPORTED_COMPRESSION, | ||
ERR_INVALID_SIGNATURE, | ||
ERR_INVALID_PASSORD, | ||
ERR_DUPLICATED_NAME, | ||
ERR_INVALID_COMMENT, | ||
ERR_INVALID_ENTRY_NAME, | ||
ERR_INVALID_ENTRY_COMMENT, | ||
ERR_INVALID_VERSION, | ||
ERR_INVALID_DATE, | ||
ERR_INVALID_EXTRAFIELD_TYPE, | ||
ERR_INVALID_EXTRAFIELD_DATA | ||
}; | ||
function getTotalSize(entries, propertyName) { | ||
let size = 0; | ||
entries.forEach(process); | ||
return size; | ||
function process(entry) { | ||
size += entry[propertyName]; | ||
if (entry.children) { | ||
entry.children.forEach(process); | ||
} | ||
} | ||
} | ||
function getZipBlobReader(options) { | ||
return class { | ||
constructor(entry) { | ||
this.entry = entry; | ||
this.size = 0; | ||
} | ||
async readUint8Array(index, length) { | ||
if (!this.blobReader) { | ||
const data = await this.entry.getData(new BlobWriter(), options); | ||
this.data = data; | ||
this.blobReader = new BlobReader(data); | ||
} | ||
return this.blobReader.readUint8Array(index, length); | ||
} | ||
async init() { | ||
this.size = this.entry.uncompressedSize; | ||
} | ||
}; | ||
} | ||
async function initReaders(entry) { | ||
if (entry.children.length) { | ||
for (const child of entry.children) { | ||
if (child.directory) { | ||
await initReaders(child); | ||
} else { | ||
child.reader = new child.Reader(child.data); | ||
await child.reader.init(); | ||
child.uncompressedSize = child.reader.size; | ||
} | ||
} | ||
} | ||
} | ||
function detach(entry) { | ||
const children = entry.parent.children; | ||
children.forEach((child, index) => { | ||
if (child.id == entry.id) | ||
children.splice(index, 1); | ||
}); | ||
} | ||
async function exportZip(zipWriter, entry, totalSize, options) { | ||
let currentIndex = 0; | ||
await process(zipWriter, entry); | ||
async function process(zipWriter, entry) { | ||
await exportChild(); | ||
async function exportChild() { | ||
let index = 0; | ||
for (const child of entry.children) { | ||
let currentIndexEntry = currentIndex; | ||
await zipWriter.add(child.getFullname(), child.reader, Object.assign({ | ||
directory: child.directory | ||
}, { | ||
onprogress: indexProgress => { | ||
if (options.onprogress) { | ||
options.onprogress(currentIndexEntry + index + indexProgress, totalSize); | ||
} | ||
} | ||
})); | ||
currentIndex += child.uncompressedSize; | ||
await process(zipWriter, child); | ||
index++; | ||
} | ||
} | ||
} | ||
} | ||
async function addFileEntry(zipEntry, fileEntry) { | ||
if (fileEntry.isDirectory) { | ||
await process(zipEntry, fileEntry); | ||
} else { | ||
await new Promise((resolve, reject) => { | ||
fileEntry.file(file => { | ||
zipEntry.addBlob(fileEntry.name, file); | ||
resolve(); | ||
}, reject); | ||
}); | ||
} | ||
function getChildren(fileEntry) { | ||
return new Promise((resolve, reject) => { | ||
let entries = []; | ||
if (fileEntry.isDirectory) { | ||
readEntries(fileEntry.createReader()); | ||
} | ||
if (fileEntry.isFile) { | ||
resolve(entries); | ||
} | ||
function readEntries(directoryReader) { | ||
directoryReader.readEntries(temporaryEntries => { | ||
if (!temporaryEntries.length) { | ||
resolve(entries); | ||
} else { | ||
entries = entries.concat(temporaryEntries); | ||
readEntries(directoryReader); | ||
} | ||
}, reject); | ||
} | ||
}); | ||
} | ||
async function process(zipEntry, fileEntry) { | ||
const children = await getChildren(fileEntry); | ||
for (const child of children) { | ||
if (child.isDirectory) { | ||
await process(zipEntry.addDirectory(child.name)); | ||
} | ||
await new Promise((resolve, reject) => { | ||
if (child.isFile) { | ||
child.file(file => { | ||
const childZipEntry = zipEntry.addBlob(child.name, file); | ||
childZipEntry.uncompressedSize = file.size; | ||
resolve(childZipEntry); | ||
}, reject); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
function resetFS(fs) { | ||
fs.entries = []; | ||
fs.root = new ZipDirectoryEntry(fs); | ||
} | ||
async function bufferedCopy(reader, writer, options) { | ||
return stepCopy(); | ||
async function stepCopy(chunkIndex = 0) { | ||
const index = chunkIndex * CHUNK_SIZE; | ||
if (options.onprogress) { | ||
options.onprogress(index, reader.size); | ||
} | ||
if (index < reader.size) { | ||
const array = await reader.readUint8Array(index, Math.min(CHUNK_SIZE, reader.size - index)); | ||
await writer.writeUint8Array(array); | ||
return stepCopy(chunkIndex + 1); | ||
} else { | ||
return writer.getData(); | ||
} | ||
} | ||
} | ||
function addChild(parent, name, params, directory) { | ||
if (parent.directory) { | ||
return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent); | ||
} else { | ||
throw new Error("Parent entry is not a directory"); | ||
} | ||
} | ||
export * from "./core/zip-fs-core.js"; |
140
lib/zip.js
@@ -29,140 +29,10 @@ /* | ||
/* global navigator */ | ||
"use strict"; | ||
import Deflate from "./codecs/deflate.js"; | ||
import Inflate from "./codecs/inflate.js"; | ||
import Deflate from "./core/codecs/deflate.js"; | ||
import Inflate from "./core/codecs/inflate.js"; | ||
import { configure } from "./core/zip-core.js"; | ||
import { | ||
Reader, | ||
Writer, | ||
TextReader, | ||
TextWriter, | ||
Data64URIReader, | ||
Data64URIWriter, | ||
BlobReader, | ||
BlobWriter, | ||
HttpReader, | ||
HttpRangeReader, | ||
Uint8ArrayReader, | ||
Uint8ArrayWriter, | ||
ERR_HTTP_RANGE | ||
} from "./stream.js"; | ||
configure({ Deflate, Inflate }); | ||
import { | ||
ZipReader as BaseZipReader, | ||
ERR_BAD_FORMAT, | ||
ERR_EOCDR_NOT_FOUND, | ||
ERR_EOCDR_ZIP64_NOT_FOUND, | ||
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, | ||
ERR_CENTRAL_DIRECTORY_NOT_FOUND, | ||
ERR_LOCAL_FILE_HEADER_NOT_FOUND, | ||
ERR_EXTRAFIELD_ZIP64_NOT_FOUND, | ||
ERR_ENCRYPTED, | ||
ERR_UNSUPPORTED_ENCRYPTION, | ||
ERR_UNSUPPORTED_COMPRESSION, | ||
ERR_INVALID_SIGNATURE, | ||
ERR_INVALID_PASSORD | ||
} from "./zip-reader.js"; | ||
import { | ||
ZipWriter as BaseZipWriter, | ||
ERR_DUPLICATED_NAME, | ||
ERR_INVALID_COMMENT, | ||
ERR_INVALID_ENTRY_NAME, | ||
ERR_INVALID_ENTRY_COMMENT, | ||
ERR_INVALID_VERSION, | ||
ERR_INVALID_DATE, | ||
ERR_INVALID_EXTRAFIELD_TYPE, | ||
ERR_INVALID_EXTRAFIELD_DATA | ||
} from "./zip-writer.js"; | ||
import { | ||
default as initShimAsyncCodec | ||
} from "./util/stream-codec-shim.js"; | ||
const DEFAULT_CONFIGURATION = { | ||
chunkSize: 512 * 1024, | ||
maxWorkers: (typeof navigator != "undefined" && navigator.hardwareConcurrency) || 2, | ||
workerScriptsPath: undefined, | ||
useWebWorkers: true, | ||
Deflate, | ||
Inflate | ||
}; | ||
let config = Object.assign({}, DEFAULT_CONFIGURATION); | ||
class ZipReader extends BaseZipReader { | ||
constructor(reader, options) { | ||
super(reader, options, config); | ||
} | ||
} | ||
class ZipWriter extends BaseZipWriter { | ||
constructor(writer, options) { | ||
super(writer, options, config); | ||
} | ||
} | ||
export { | ||
configure, | ||
initShimAsyncCodec, | ||
getMimeType, | ||
ZipReader, | ||
ZipWriter, | ||
Reader, | ||
Writer, | ||
TextReader, | ||
TextWriter, | ||
Data64URIReader, | ||
Data64URIWriter, | ||
BlobReader, | ||
BlobWriter, | ||
HttpReader, | ||
HttpRangeReader, | ||
Uint8ArrayWriter, | ||
Uint8ArrayReader, | ||
ERR_HTTP_RANGE, | ||
ERR_BAD_FORMAT, | ||
ERR_EOCDR_NOT_FOUND, | ||
ERR_EOCDR_ZIP64_NOT_FOUND, | ||
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, | ||
ERR_CENTRAL_DIRECTORY_NOT_FOUND, | ||
ERR_LOCAL_FILE_HEADER_NOT_FOUND, | ||
ERR_EXTRAFIELD_ZIP64_NOT_FOUND, | ||
ERR_ENCRYPTED, | ||
ERR_UNSUPPORTED_ENCRYPTION, | ||
ERR_UNSUPPORTED_COMPRESSION, | ||
ERR_INVALID_SIGNATURE, | ||
ERR_INVALID_PASSORD, | ||
ERR_DUPLICATED_NAME, | ||
ERR_INVALID_COMMENT, | ||
ERR_INVALID_ENTRY_NAME, | ||
ERR_INVALID_ENTRY_COMMENT, | ||
ERR_INVALID_VERSION, | ||
ERR_INVALID_DATE, | ||
ERR_INVALID_EXTRAFIELD_TYPE, | ||
ERR_INVALID_EXTRAFIELD_DATA | ||
}; | ||
function configure(configuration) { | ||
config = Object.assign({}, config, configuration); | ||
if (config.workerScripts != null && config.workerScriptsPath != null) { | ||
throw new Error("Either workerScripts or workerScriptsPath may be set, not both"); | ||
} | ||
if (config.workerScripts) { | ||
if (config.workerScripts.deflate && !Array.isArray(config.workerScripts.deflate)) { | ||
throw new Error("workerScripts.deflate must be an array"); | ||
} | ||
if (config.workerScripts.inflate && !Array.isArray(config.workerScripts.inflate)) { | ||
throw new Error("workerScripts.inflate must be an array"); | ||
} | ||
} | ||
} | ||
function getMimeType() { | ||
return "application/octet-stream"; | ||
} | ||
export * from "./core/zip-core.js"; |
@@ -6,3 +6,3 @@ { | ||
"license": "BSD-3-Clause", | ||
"version": "2.0.12", | ||
"version": "2.1.0", | ||
"keywords": [ | ||
@@ -9,0 +9,0 @@ "zip", |
@@ -24,2 +24,38 @@ import { terser } from "rollup-plugin-terser"; | ||
}, { | ||
input: "lib/zip-workers.js", | ||
output: [ | ||
{ | ||
file: "dist/zip-workers.min.js", | ||
format: "umd", | ||
name: "zip", | ||
plugins: [ | ||
terser() | ||
] | ||
} | ||
] | ||
}, { | ||
input: "lib/zip-inflate.js", | ||
output: [ | ||
{ | ||
file: "dist/zip-inflate.min.js", | ||
format: "umd", | ||
name: "zip", | ||
plugins: [ | ||
terser() | ||
] | ||
} | ||
] | ||
}, { | ||
input: "lib/zip-deflate.js", | ||
output: [ | ||
{ | ||
file: "dist/zip-deflate.min.js", | ||
format: "umd", | ||
name: "zip", | ||
plugins: [ | ||
terser() | ||
] | ||
} | ||
] | ||
}, { | ||
input: "lib/zip-fs.js", | ||
@@ -67,2 +103,24 @@ output: [ | ||
}, { | ||
input: "lib/z-worker-inflate.js", | ||
output: [ | ||
{ | ||
file: "dist/z-worker-inflate.js", | ||
format: "iife", | ||
plugins: [ | ||
terser() | ||
] | ||
} | ||
] | ||
}, { | ||
input: "lib/z-worker-deflate.js", | ||
output: [ | ||
{ | ||
file: "dist/z-worker-deflate.js", | ||
format: "iife", | ||
plugins: [ | ||
terser() | ||
] | ||
} | ||
] | ||
}, { | ||
input: "lib/z-worker-pako.js", | ||
@@ -69,0 +127,0 @@ output: [ |
@@ -16,3 +16,3 @@ /* eslint-disable no-console */ | ||
workerScripts: { | ||
deflate: ["../../dist/z-worker-pako.js", "../vendor/pako_deflate.min.js"], | ||
deflate: ["../../dist/z-worker-pako.js", "../../tests/vendor/pako_deflate.min.js"], | ||
inflate: ["../../dist/z-worker.js"] | ||
@@ -19,0 +19,0 @@ } |
@@ -13,3 +13,9 @@ /* eslint-disable no-console */ | ||
document.body.innerHTML = "..."; | ||
zip.configure({ chunkSize: 128 }); | ||
zip.configure({ | ||
chunkSize: 128, | ||
workerScripts: { | ||
deflate: ["../../dist/z-worker-deflate.js"], | ||
inflate: ["../../dist/z-worker-inflate.js"] | ||
} | ||
}); | ||
let zipFs = new zip.fs.FS(); | ||
@@ -16,0 +22,0 @@ let directory = zipFs.root.addDirectory("import"); |
@@ -14,6 +14,6 @@ /* eslint-disable no-console */ | ||
document.body.innerHTML = "..."; | ||
zip.configure({ | ||
zip.configure({ | ||
workerScripts: { | ||
deflate: ["../../dist/z-worker-pako.js", "../vendor/pako_deflate.min.js"], | ||
inflate: ["../../dist/z-worker-pako.js", "../vendor/pako_inflate.min.js"] | ||
deflate: ["../../dist/z-worker-pako.js", "../../tests/vendor/pako_deflate.min.js"], | ||
inflate: ["../../dist/z-worker-pako.js", "../../tests/vendor/pako_inflate.min.js"] | ||
} | ||
@@ -20,0 +20,0 @@ }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110
1163833
18355
7
10