diff --git a/jszip/jszip-tests.ts b/jszip/jszip-tests.ts
index 9222cbb5b..97fd10450 100644
--- a/jszip/jszip-tests.ts
+++ b/jszip/jszip-tests.ts
@@ -1,4 +1,3 @@
-///
///
var SEVERITY = {
@@ -10,30 +9,29 @@ var SEVERITY = {
}
function testJSZip() {
-
var newJszip = new JSZip();
newJszip.file("test.txt", "test string");
newJszip.file("test/test.txt", "test string");
- var serializedZip = newJszip.generate({compression: "DEFLATE", type:"base64"});
+ var serializedZip = newJszip.generate({compression: "DEFLATE", type: "base64"});
newJszip = new JSZip();
newJszip.load(serializedZip, {base64: true, checkCRC32: true});
- if(newJszip.file("test.txt").data === "test string") {
+ if (newJszip.file("test.txt").asText() === "test string") {
log(SEVERITY.INFO, "all ok");
} else {
log(SEVERITY.ERROR, "no matching file found");
}
- if(newJszip.file("test/test.txt").data === "test string") {
+ if (newJszip.file("test/test.txt").asText() === "test string") {
log(SEVERITY.INFO, "all ok");
} else {
log(SEVERITY.ERROR, "no matching file found");
}
var folder = newJszip.folder("test");
- if(folder.file("test.txt").data == "test string") {
+ if(folder.file("test.txt").asText() == "test string") {
log(SEVERITY.INFO, "all ok");
}
else {
@@ -44,7 +42,7 @@ function testJSZip() {
if(folders.length == 1) {
log(SEVERITY.INFO, "all ok");
- if(folders[0].options.dir == true) {
+ if(folders[0].dir == true) {
log(SEVERITY.INFO, "all ok");
}
else {
@@ -57,7 +55,7 @@ function testJSZip() {
var files = newJszip.file(new RegExp("^test"));
if(files.length == 2) {
log(SEVERITY.INFO, "all ok");
- if(files[0].data == "test string" && files[1].data == "test string") {
+ if (files[0].asText() == "test string" && files[1].asText() == "test string") {
log(SEVERITY.INFO, "all ok");
}
else {
@@ -68,11 +66,11 @@ function testJSZip() {
log(SEVERITY.ERROR, "wrong number of files");
}
- var filterFiles = newJszip.filter((relativePath: string, file: jszip.JSZipFile) => {
- if(file.data == "test string") {
- return true;
- }
- return false;
+ var filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => {
+ if (file.asText() == "test string") {
+ return true;
+ }
+ return false;
});
if(filterFiles.length == 2) {
@@ -84,11 +82,11 @@ function testJSZip() {
newJszip.remove("test/test.txt");
- filterFiles = newJszip.filter((relativePath: string, file: jszip.JSZipFile) => {
- if(file.data == "test string") {
- return true;
- }
- return false;
+ filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => {
+ if (file.asText() == "test string") {
+ return true;
+ }
+ return false;
});
if(filterFiles.length == 1) {
@@ -97,11 +95,6 @@ function testJSZip() {
else {
log(SEVERITY.ERROR, "wrong number of files");
}
-
- log(SEVERITY.INFO, newJszip.crc32("Test"));
- log(SEVERITY.INFO, newJszip.utf8encode("Test"));
- log(SEVERITY.INFO, newJszip.utf8decode("Test"));
- newJszip.clone();
}
function log(severity:number, message: any) {
diff --git a/jszip/jszip.d.ts b/jszip/jszip.d.ts
index 4c571dc95..038b52957 100644
--- a/jszip/jszip.d.ts
+++ b/jszip/jszip.d.ts
@@ -3,181 +3,170 @@
// Definitions by: mzeiher
// Definitions: https://github.com/borisyankov/DefinitelyTyped
-declare module jszip {
- export interface JSZip {
- /**
- * Get a file from the archive
- *
- * @param path {string} relative path to file
- *
- * @return {JSZipFile} file matching path, null if no file found
- */
- file(path: string): JSZipFile;
+interface JSZip {
+ /**
+ * Get a file from the archive
+ *
+ * @param Path relative path to file
+ * @return File matching path, null if no file found
+ */
+ file(path: string): JSZipObject;
- /**
- * Get files matching a RegExp from archive
- *
- * @param path {RegExp} RegExp to match
- *
- * @return {JSZipFile[]} return all matching files or an empty array
- */
- file(path: RegExp): JSZipFile[];
+ /**
+ * Get files matching a RegExp from archive
+ *
+ * @param path RegExp to match
+ * @return Return all matching files or an empty array
+ */
+ file(path: RegExp): JSZipObject[];
- /**
- * Add a file to the archive
- *
- * @param path {string} relative path to file
- * @param content {any} content of the file
- * @param options {JSZipOptions} optional information about the file
- *
- * @return {JSZip} JSZip object
- */
- file(path: string, content: any, options?: JSZipOptions): JSZip;
+ /**
+ * Add a file to the archive
+ *
+ * @param path Relative path to file
+ * @param content Content of the file
+ * @param options Optional information about the file
+ * @return JSZip object
+ */
+ file(path: string, data: any, options?: JSZipFileOptions): JSZip;
- /**
- * Return an new JSZip instance with the given folder as root
- *
- * @param name {string} name of the folder
- *
- * @return {JSZip} new JSZip object with the given folder as root or null
- */
- folder(name: string): JSZip;
+ /**
+ * Return an new JSZip instance with the given folder as root
+ *
+ * @param name Name of the folder
+ * @return New JSZip object with the given folder as root or null
+ */
+ folder(name: string): JSZip;
- /**
- * Returns new JSZip instances with the matching folders as root
- *
- * @param name {RegExp} RegExp to match
- *
- * @return {JSZipFile[]} new array of JSZipFile objects which match the RegExp
- */
- folder(name: RegExp): JSZipFile[];
+ /**
+ * Returns new JSZip instances with the matching folders as root
+ *
+ * @param name RegExp to match
+ * @return New array of JSZipFile objects which match the RegExp
+ */
+ folder(name: RegExp): JSZipObject[];
- /**
- * Removes the file or folder from the archive
- *
- * @param path {string} relative path of file or folder
- *
- * @return {JSZip} returns the JSZip instance
- */
- remove(path: string): JSZip;
+ /**
+ * Get all files wchich match the given filter function
+ *
+ * @param predicate Filter function
+ * @return Array of matched elements
+ */
+ filter(predicate: (relativePath: string, file: JSZipObject) => boolean): JSZipObject[];
- /**
- * Generates a new archive
- *
- * @param options {JSZipGeneratorOptions} optional options for the generator
- *
- * @return {any} the serialized archive
- */
- generate(options?: JSZipGeneratorOptions): any;
+ /**
+ * Removes the file or folder from the archive
+ *
+ * @param path Relative path of file or folder
+ * @return Returns the JSZip instance
+ */
+ remove(path: string): JSZip;
- /**
- * Deserialize zip file
- *
- * @param data {any} serialized zip file
- * @param options {JSZipOptions} options for deserializing
- *
- * @return {JSZip} returns the JSZip instance
- */
- load(data: any, options: JSZipOptions): JSZip;
+ /**
+ * Generates a new archive
+ *
+ * @param options Optional options for the generator
+ * @return The serialized archive
+ */
+ generate(options?: JSZipGeneratorOptions): any;
- /**
- * Get all files wchich match the given filter function
- *
- * @param {function} filter function
- *
- * @return {JSZipFile[]} array of matched elements
- */
- filter(predicate: (relativePath: string, file: JSZipFile) => boolean): JSZipFile[];
+ /**
+ * Deserialize zip file
+ *
+ * @param data Serialized zip file
+ * @param options Options for deserializing
+ * @return Returns the JSZip instance
+ */
+ load(data: any, options: JSZipLoadOptions): JSZip;
+}
- /**
- * Calculate crc32 of given string
- *
- * @param data {string} string to calculate crc32 from
- * @param crc {number} optional: initializer for crc calc
- *
- * @return {number} calculated crc32 number
- */
- crc32(data: string, crc?: number): number;
+interface JSZipObject {
+ name: string;
+ dir: boolean;
+ date: Date;
+ comment: string;
+ options: JSZipObjectOptions;
- /**
- * Clone JSSZip instance
- *
- * return {JSZip} cloned instsance
- */
- clone(): JSZip;
+ asText(): string;
+ asBinary(): string;
+ asArrayBuffer(): ArrayBuffer;
+ asUint8Array(): Uint8Array;
+ //asNodeBuffer(): Buffer;
+}
- /**
- * UTF8 encode a string
- *
- * @param data {string} string to encode
- */
- utf8encode(data: string): string;
+interface JSZipFileOptions {
+ base64?: boolean;
+ binary?: boolean;
+ date?: Date;
+ compression?: string;
+ comment?: string;
+ optimizedBinaryString?: boolean;
+ createFolders?: boolean;
+}
- /**
- * UTF8 decode a string
- *
- * @param data {string} string to decode
- */
- utf8decode(data: string): string;
+interface JSZipObjectOptions {
+ /** deprecated */
+ base64: boolean;
+ /** deprecated */
+ binary: boolean;
+ /** deprecated */
+ dir: boolean;
+ /** deprecated */
+ date: Date;
+ compression: string;
+}
- }
+interface JSZipGeneratorOptions {
+ /** deprecated */
+ base64?: boolean;
+ /** DEFLATE or STORE */
+ compression?: string;
+ /** base64 (default), string, uint8array, blob */
+ type?: string;
+ comment?: string;
+}
- export interface JSZipSupport {
- arraybuffer: boolean;
- uint8array: boolean;
- blob: boolean;
- }
+interface JSZipLoadOptions {
+ base64?: boolean;
+ checkCRC32?: boolean;
+ optimizedBinaryString?: boolean;
+ createFolders?: boolean;
+}
- export interface JSZipGeneratorOptions {
- base64?: boolean; //deprecated
- compression: string; //DEFLATE or STORE
- type: string; //base64 (default), string, uint8array, blob
- }
-
- export interface JSZipOptions {
- base64: boolean;
- checkCRC32: boolean;
- }
-
- export interface JSZipFile {
- name: string;
- data: any;
- options: JSZipFileOptions;
-
- asText(): string;
- asBinary(): any;
- asArrayBuffer(): ArrayBuffer;
- asUint8Array(): Uint8Array;
- }
-
- export interface JSZipFileOptions {
- base64: boolean;
- binary: boolean;
- dir: boolean;
- date: Date;
- }
-
- export interface JSZipBase64 {
- }
+interface JSZipSupport {
+ arraybuffer: boolean;
+ uint8array: boolean;
+ blob: boolean;
+ nodebuffer: boolean;
}
declare var JSZip: {
+ /**
+ * Create JSZip instance
+ */
+ (): JSZip;
/**
* Create JSZip instance
* If no parameters given an empty zip archive will be created
*
- * @param data {any} serialized zip archive
- * @param options {JSZipOptions} description of the serialized zip archive
+ * @param data Serialized zip archive
+ * @param options Description of the serialized zip archive
*/
- new(data?: any, options?: jszip.JSZipOptions): jszip.JSZip;
+ (data: any, options?: JSZipLoadOptions): JSZip;
- prototype: jszip.JSZip;
- support : jszip.JSZipSupport;
-}
+ /**
+ * Create JSZip instance
+ */
+ new (): JSZip;
+ /**
+ * Create JSZip instance
+ * If no parameters given an empty zip archive will be created
+ *
+ * @param data Serialized zip archive
+ * @param options Description of the serialized zip archive
+ */
+ new (data: any, options?: JSZipLoadOptions): JSZip;
-declare var JSZipBase64: {
- encode(input: string, utf8?: any): string;
- decode(input: string, utf8?: any): string;
-
- prototype: jszip.JSZipBase64;
+ prototype: JSZip;
+ support: JSZipSupport;
}
\ No newline at end of file