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

PDFDoc() now detects argument type #542

Merged
merged 1 commit into from
Sep 27, 2011
Merged
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
22 changes: 18 additions & 4 deletions pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ var Stream = (function streamStream() {
},
makeSubStream: function stream_makeSubstream(start, length, dict) {
return new Stream(this.bytes.buffer, start, length, dict);
}
},
isStream: true
};

return constructor;
Expand Down Expand Up @@ -3800,8 +3801,21 @@ var Catalog = (function catalogCatalog() {
})();

var PDFDoc = (function pdfDoc() {
function constructor(data) {
var stream = new Stream(data);
function constructor(arg, callback) {
// Stream argument
if (typeof arg.isStream !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be |typeof arg.isStream !== 'undefined' && arg.isStream| ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose someone could really mess with us and add a isStream = false to an object... So, yep :)

Or more simply: if (arg.isStream). I just added typeof for consistency with the test below it (ArrayBuffer type).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgjones I was just about to fix this :) oh well, I guess it's no biggie.

init.call(this, arg);
}
// ArrayBuffer argument
else if (typeof arg.byteLength !== 'undefined') {
init.call(this, new Stream(arg));
}
else {
error('Unknown argument type');
}
}

function init(stream){
assertWellFormed(stream.length > 0, 'stream must have data');
this.stream = stream;
this.setup();
Expand All @@ -3822,7 +3836,7 @@ var PDFDoc = (function pdfDoc() {
stream.pos += index;
return true; /* found */
}

constructor.prototype = {
get linearization() {
var length = this.stream.length;
Expand Down