Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error without type in async() #481

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions lib/zipObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,29 @@ ZipObject.prototype = {
* @return StreamHelper the stream.
*/
internalStream: function (type) {
var outputType = type.toLowerCase();
var askUnicodeString = outputType === "string" || outputType === "text";
if (outputType === "binarystring" || outputType === "text") {
outputType = "string";
}
var result = this._decompressWorker();
var result = null, outputType = "string";
try {
if (!type) {
throw new Error("No output type specified.");
}
outputType = type.toLowerCase();
var askUnicodeString = outputType === "string" || outputType === "text";
if (outputType === "binarystring" || outputType === "text") {
outputType = "string";
}
result = this._decompressWorker();

var isUnicodeString = !this._dataBinary;
var isUnicodeString = !this._dataBinary;

if (isUnicodeString && !askUnicodeString) {
result = result.pipe(new utf8.Utf8EncodeWorker());
}
if (!isUnicodeString && askUnicodeString) {
result = result.pipe(new utf8.Utf8DecodeWorker());
if (isUnicodeString && !askUnicodeString) {
result = result.pipe(new utf8.Utf8EncodeWorker());
}
if (!isUnicodeString && askUnicodeString) {
result = result.pipe(new utf8.Utf8DecodeWorker());
}
} catch (e) {
result = new GenericWorker("error");
result.error(e);
}

return new StreamHelper(result, outputType, "");
Expand Down
6 changes: 6 additions & 0 deletions test/asserts/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ QUnit.module("file", function () {
_actualTestFileDataGetters.testGetter(opts, "nodebuffer");
_actualTestFileDataGetters.testGetter(opts, "blob");
_actualTestFileDataGetters.testGetter(opts, "unknown");
_actualTestFileDataGetters.testGetter(opts, null);

stop();
opts.zip.generateAsync({type:"binarystring"})
Expand All @@ -162,6 +163,7 @@ QUnit.module("file", function () {
_actualTestFileDataGetters.testGetter(reloaded, "nodebuffer");
_actualTestFileDataGetters.testGetter(reloaded, "blob");
_actualTestFileDataGetters.testGetter(reloaded, "unknown");
_actualTestFileDataGetters.testGetter(reloaded, null);

opts.zip.file("file.txt", "changing the content after the call won't change the result");
start();
Expand Down Expand Up @@ -253,6 +255,10 @@ QUnit.module("file", function () {
assert_unknown : function (opts, err, buffer, testName) {
equal(buffer, null, testName + "no data");
ok(err.message.match("not supported by this platform"), testName + "the error message is useful");
},
assert_null : function (opts, err, buffer, testName) {
equal(buffer, null, testName + "no data");
ok(err.message.match("No output type specified"), testName + "the error message is useful");
}
};

Expand Down