Skip to content

Commit

Permalink
Merge pull request #481 from dduponchel/no_type
Browse files Browse the repository at this point in the history
Improve the error without type in async()
  • Loading branch information
dduponchel committed Nov 8, 2017
2 parents a4c7e04 + 440ddd3 commit ece381a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
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

0 comments on commit ece381a

Please sign in to comment.