Commit a8c99525 authored by rockyl's avatar rockyl

init

parent 06b7c1b3
# Created by .ignore support plugin (hsz.mobi)
/src/
/tiny-image.iml
/test.js
/**
* Created by rockyl on 2020-02-13.
*/
export declare function compressBuffer(buffer: any): Promise<unknown>;
export declare function compressFile(file: any): Promise<unknown>;
...@@ -29,12 +29,18 @@ async function compressBuffer(buffer) { ...@@ -29,12 +29,18 @@ async function compressBuffer(buffer) {
resBuffer = Buffer.concat([resBuffer, d], resBuffer.length + d.length); resBuffer = Buffer.concat([resBuffer, d], resBuffer.length + d.length);
}); });
res.on('end', () => { res.on('end', () => {
if (isPng(resBuffer) || isJpg(resBuffer)) { if (resBuffer.length > 256 || isPng(resBuffer) || isJpg(resBuffer)) {
resolve(resBuffer); resolve(resBuffer);
} }
else { else {
let str = resBuffer.toString(); let str = resBuffer.toString();
let json = JSON.parse(str); let json;
try {
json = JSON.parse(str);
}
catch (e) {
console.log(e);
}
reject(json.msg); reject(json.msg);
} }
}); });
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACtC,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEhC,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAE/C,KAAK,UAAU,cAAc,CAAC,MAAM;IAC1C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAChC,IAAI,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7C,IAAI,IAAI,GAAG,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"}
\ No newline at end of file \ No newline at end of file
{ {
"name": "tiny-image", "name": "tiny-image",
"version": "1.0.0", "version": "1.0.1",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"license": "MIT", "license": "MIT",
......
...@@ -29,11 +29,16 @@ export async function compressBuffer(buffer) { ...@@ -29,11 +29,16 @@ export async function compressBuffer(buffer) {
resBuffer = Buffer.concat([resBuffer, d], resBuffer.length + d.length); resBuffer = Buffer.concat([resBuffer, d], resBuffer.length + d.length);
}); });
res.on('end', () => { res.on('end', () => {
if(isPng(resBuffer) || isJpg(resBuffer)){ if(resBuffer.length > 256 || isPng(resBuffer) || isJpg(resBuffer)){
resolve(resBuffer); resolve(resBuffer);
} else { } else {
let str = resBuffer.toString(); let str = resBuffer.toString();
let json = JSON.parse(str); let json;
try {
json = JSON.parse(str);
}catch (e){
console.log(e);
}
reject(json.msg); reject(json.msg);
} }
}); });
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"strictNullChecks": true, "strictNullChecks": true,
"target": "ES2017", "target": "ES2017",
"traceResolution": false, "traceResolution": false,
"types" : ["node"] "types" : ["node"],
"declaration": true
}, },
"include": [ "include": [
"./src" "./src"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment