mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 19:12:20 +08:00
Merge pull request #4386 from legokichi/master
JSZip.compressions.DEFLATE added
This commit is contained in:
@@ -33,18 +33,18 @@ function testJSZip() {
|
||||
var folder = newJszip.folder("test");
|
||||
if(folder.file("test.txt").asText() == "test string") {
|
||||
log(SEVERITY.INFO, "all ok");
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(SEVERITY.ERROR, "wrong file");
|
||||
}
|
||||
|
||||
var folders = newJszip.folder(new RegExp("^test"));
|
||||
|
||||
|
||||
if(folders.length == 1) {
|
||||
log(SEVERITY.INFO, "all ok");
|
||||
if(folders[0].dir == true) {
|
||||
log(SEVERITY.INFO, "all ok");
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(SEVERITY.ERROR, "wrong file");
|
||||
}
|
||||
@@ -59,14 +59,14 @@ function testJSZip() {
|
||||
log(SEVERITY.INFO, "all ok");
|
||||
}
|
||||
else {
|
||||
log(SEVERITY.ERROR, "wrong data in files");
|
||||
log(SEVERITY.ERROR, "wrong data in files");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(SEVERITY.ERROR, "wrong number of files");
|
||||
}
|
||||
|
||||
var filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => {
|
||||
var filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => {
|
||||
if (file.asText() == "test string") {
|
||||
return true;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function testJSZip() {
|
||||
|
||||
newJszip.remove("test/test.txt");
|
||||
|
||||
filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => {
|
||||
filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => {
|
||||
if (file.asText() == "test string") {
|
||||
return true;
|
||||
}
|
||||
@@ -95,24 +95,43 @@ function testJSZip() {
|
||||
else {
|
||||
log(SEVERITY.ERROR, "wrong number of files");
|
||||
}
|
||||
|
||||
var uncompressedStr = JSZip.compressions.DEFLATE.uncompress(
|
||||
JSZip.compressions.DEFLATE.compress("\0\1\2\3\4\5\6\7",{level:9}));
|
||||
var uncompressedArr = JSZip.compressions.DEFLATE.uncompress(
|
||||
JSZip.compressions.DEFLATE.compress([0,1,2,3,4,5,6,7],{level:9}));
|
||||
var uncompressedUint8Arr = JSZip.compressions.DEFLATE.uncompress(
|
||||
JSZip.compressions.DEFLATE.compress(new Uint8Array([0,1,2,3,4,5,6,7]),{level:9}));
|
||||
|
||||
var every_match = [0,1,2,3,4,5,6,7].every(function(val, i){
|
||||
return uncompressedStr[i] === val &&
|
||||
uncompressedArr[i] === val &&
|
||||
uncompressedUint8Arr[i] === val;
|
||||
});
|
||||
if(every_match) {
|
||||
log(SEVERITY.INFO, "compress and uncompress ok.");
|
||||
}else{
|
||||
log(SEVERITY.ERROR, "compress or uncompress failed.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function log(severity:number, message: any) {
|
||||
var log = "";
|
||||
switch(severity) {
|
||||
case 0:
|
||||
case 0:
|
||||
log += "[DEBUG] ";
|
||||
break;
|
||||
case 1:
|
||||
case 1:
|
||||
log += "[INFO] ";
|
||||
break;
|
||||
case 2:
|
||||
case 2:
|
||||
log += "[WARN] ";
|
||||
break;
|
||||
case 3:
|
||||
case 3:
|
||||
log += "[ERROR] ";
|
||||
break;
|
||||
case 4:
|
||||
case 4:
|
||||
log += "[FATAL] ";
|
||||
break;
|
||||
default:
|
||||
@@ -122,4 +141,4 @@ function log(severity:number, message: any) {
|
||||
console.log(log += message);
|
||||
}
|
||||
|
||||
testJSZip();
|
||||
testJSZip();
|
||||
|
||||
21
jszip/jszip.d.ts
vendored
21
jszip/jszip.d.ts
vendored
@@ -32,7 +32,7 @@ interface 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
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ interface JSZip {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -56,7 +56,7 @@ interface JSZip {
|
||||
|
||||
/**
|
||||
* Removes the file or folder from the archive
|
||||
*
|
||||
*
|
||||
* @param path Relative path of file or folder
|
||||
* @return Returns the JSZip instance
|
||||
*/
|
||||
@@ -140,6 +140,18 @@ interface JSZipSupport {
|
||||
nodebuffer: boolean;
|
||||
}
|
||||
|
||||
interface DEFLATE {
|
||||
/** pako.deflateRaw, level:0-9 */
|
||||
compress(input: string, compressionOptions: {level:number}): Uint8Array;
|
||||
compress(input: number[], compressionOptions: {level:number}): Uint8Array;
|
||||
compress(input: Uint8Array, compressionOptions: {level:number}): Uint8Array;
|
||||
|
||||
/** pako.inflateRaw */
|
||||
uncompress(input: string): Uint8Array;
|
||||
uncompress(input: number[]): Uint8Array;
|
||||
uncompress(input: Uint8Array): Uint8Array;
|
||||
}
|
||||
|
||||
declare var JSZip: {
|
||||
/**
|
||||
* Create JSZip instance
|
||||
@@ -169,6 +181,9 @@ declare var JSZip: {
|
||||
|
||||
prototype: JSZip;
|
||||
support: JSZipSupport;
|
||||
compressions: {
|
||||
DEFLATE: DEFLATE;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "jszip" {
|
||||
|
||||
Reference in New Issue
Block a user