mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
added zip.js def files
This commit is contained in:
parent
0acdbea7fd
commit
d4138db108
3
.gitignore
vendored
3
.gitignore
vendored
@ -32,6 +32,9 @@ _infrastructure/tests/build
|
||||
#rx.js
|
||||
!rx.js
|
||||
|
||||
#zip.js
|
||||
!zip.js
|
||||
|
||||
node_modules
|
||||
|
||||
.sublimets
|
||||
|
||||
43
zip.js/zip.js-tests.ts
Normal file
43
zip.js/zip.js-tests.ts
Normal file
@ -0,0 +1,43 @@
|
||||
// create the blob object storing the data to compress
|
||||
var blob = new Blob([ "Lorem ipsum dolor sit amet, consectetuer adipiscing elit..." ], {
|
||||
type : "text/plain"
|
||||
});
|
||||
// creates a zip storing the file "lorem.txt" with blob as data
|
||||
// the zip will be stored into a Blob object (zippedBlob)
|
||||
zipBlob("lorem.txt", blob, function(zippedBlob) {
|
||||
// unzip the first file from zipped data stored in zippedBlob
|
||||
unzipBlob(zippedBlob, function(unzippedBlob) {
|
||||
// logs the uncompressed Blob
|
||||
console.log(unzippedBlob);
|
||||
});
|
||||
});
|
||||
|
||||
function zipBlob(filename, blob, callback) {
|
||||
// use a zip.BlobWriter object to write zipped data into a Blob object
|
||||
zip.createWriter(new zip.BlobWriter("application/zip"), function(zipWriter) {
|
||||
// use a BlobReader object to read the data stored into blob variable
|
||||
zipWriter.add(filename, new zip.BlobReader(blob), function() {
|
||||
// close the writer and calls callback function
|
||||
zipWriter.close(callback);
|
||||
});
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function unzipBlob(blob, callback) {
|
||||
// use a zip.BlobReader object to read zipped data stored into blob variable
|
||||
zip.createReader(new zip.BlobReader(blob), function(zipReader) {
|
||||
// get entries from the zip file
|
||||
zipReader.getEntries(function(entries) {
|
||||
// get data from the first file
|
||||
entries[0].getData(new zip.BlobWriter("text/plain"), function(data) {
|
||||
// close the reader and calls callback function with uncompressed data as parameter
|
||||
zipReader.close();
|
||||
callback(data);
|
||||
});
|
||||
});
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function onerror(message) {
|
||||
console.error(message);
|
||||
}
|
||||
92
zip.js/zip.js.d.ts
vendored
Normal file
92
zip.js/zip.js.d.ts
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
// Type definitions for zip.js 2.x
|
||||
// Project: https://github.com/gildas-lormeau/zip.js
|
||||
// Definitions by: Louis Grignon <https://github.com/lgrignon>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module zip {
|
||||
export var useWebWorkers: boolean;
|
||||
export var workerScriptsPath: string;
|
||||
export var workerScripts: {
|
||||
deflater?: string[];
|
||||
inflater?: string[];
|
||||
};
|
||||
|
||||
export class Reader {
|
||||
public size: number;
|
||||
public init(callback: () => void, onerror: (error) => void): void;
|
||||
public readUint8Array(index: number, length: number, callback: (result: Uint8Array) => void, onerror?: (error) => void): void;
|
||||
}
|
||||
|
||||
export class TextReader extends Reader {
|
||||
constructor(text: string);
|
||||
}
|
||||
|
||||
export class BlobReader extends Reader {
|
||||
constructor(blob: Blob);
|
||||
}
|
||||
|
||||
export class Data64URIReader extends Reader {
|
||||
constructor(dataURI: string);
|
||||
}
|
||||
|
||||
export class HttpReader extends Reader {
|
||||
constructor(url: string);
|
||||
}
|
||||
|
||||
export function createReader(reader: zip.Reader, callback: (zipReader: ZipReader) => void, onerror?: (error) => void): void;
|
||||
|
||||
export class ZipReader {
|
||||
getEntries(callback: (entries: zip.Entry[]) => void);
|
||||
close(callback: () => void): void;
|
||||
}
|
||||
|
||||
export interface Entry {
|
||||
filename: string;
|
||||
directory: boolean;
|
||||
compressedSize: number;
|
||||
uncompressedSize: number;
|
||||
lastModDate: Date;
|
||||
lastModDateRaw: number;
|
||||
comment: string;
|
||||
crc32: number;
|
||||
|
||||
getData(writer: zip.Writer, onend: (result: any) => void, onprogress?: (progress: number, total: number) => void, checkCrc32?: boolean): void;
|
||||
}
|
||||
|
||||
export class Writer {
|
||||
public init(callback: () => void, onerror?: (error) => void): void;
|
||||
public writeUint8Array(array: Uint8Array, callback: () => void, onerror?: (error) => void): void;
|
||||
public getData(callback: (data) => void, onerror?: (error) => void);
|
||||
}
|
||||
|
||||
export class TextWriter extends Writer {
|
||||
constructor(encoding: string);
|
||||
}
|
||||
|
||||
export class BlobWriter extends Writer {
|
||||
constructor(contentType: string);
|
||||
}
|
||||
|
||||
export class FileWriter extends Writer {
|
||||
constructor(fileEntry: FileEntry);
|
||||
}
|
||||
|
||||
export class Data64URIWriter extends Writer {
|
||||
constructor(mimeString?: string);
|
||||
}
|
||||
|
||||
export function createWriter(writer: zip.Writer, callback: (zipWriter: zip.ZipWriter) => void, onerror?: (error) => void, dontDeflate?: boolean): void;
|
||||
|
||||
export interface WriteOptions {
|
||||
directory?: boolean;
|
||||
level?: number;
|
||||
comment?: string;
|
||||
lastModDate?: Date;
|
||||
version?: number;
|
||||
}
|
||||
|
||||
export class ZipWriter {
|
||||
public add(name: string, reader: zip.Reader, onend: () => void, onprogress?: (progress: number, total: number) => void, options?: WriteOptions): void;
|
||||
public close(callback: (result: any) => void): void;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user