muhammara 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.2.0] - 2022-10-26
11
+
12
+ ### Added
13
+
14
+ - Add electron 20.3.3
15
+ - Ignore extra data above the header and below the footer in PDF Parser
16
+ - Add node 19.0.0
17
+
18
+ ## [3.1.1] - 2022-10-23
19
+
20
+ ### Fixed
21
+
22
+ - NPE in parser when file ends before it really starts
23
+
10
24
  ## [3.1.0] - 2022-09-30
11
25
 
12
26
  ### Changed
@@ -42,6 +56,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
42
56
  - Node < 11 and Electron < 11 removed
43
57
  - Renamed typo exported value from eTokenSeprator to eTokenSeparator
44
58
 
59
+ ## [2.6.1] - 2022-10-23
60
+
61
+ ### Fixed
62
+
63
+ - Backport: NPE in parser when file ends before it really starts
64
+
45
65
  ## [2.6.0] - 2022-06-30
46
66
 
47
67
  ### Changed
@@ -274,9 +294,12 @@ with the following changes.
274
294
 
275
295
  - Initial release
276
296
 
277
- [unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.1.0...HEAD
297
+ [unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.2.0...HEAD
298
+ [3.2.0]: https://github.com/julianhille/MuhammaraJS/compare/3.1.1...3.2.0
299
+ [3.1.1]: https://github.com/julianhille/MuhammaraJS/compare/3.1.0...3.1.1
278
300
  [3.1.0]: https://github.com/julianhille/MuhammaraJS/compare/3.0.0...3.1.0
279
- [3.0.0]: https://github.com/julianhille/MuhammaraJS/compare/2.6.0...3.0.0
301
+ [3.0.0]: https://github.com/julianhille/MuhammaraJS/compare/2.6.1...3.0.0
302
+ [2.6.1]: https://github.com/julianhille/MuhammaraJS/compare/2.6.0...2.6.1
280
303
  [2.6.0]: https://github.com/julianhille/MuhammaraJS/compare/2.5.0...2.6.0
281
304
  [2.5.0]: https://github.com/julianhille/MuhammaraJS/compare/2.4.0...2.5.0
282
305
  [2.4.0]: https://github.com/julianhille/MuhammaraJS/compare/2.3.0...2.4.0
@@ -8,6 +8,7 @@ function PDFRStreamForBuffer(buffer) {
8
8
  this.innerArray = Array.prototype.slice.call(buffer, 0);
9
9
  this.rposition = 0;
10
10
  this.fileSize = this.innerArray.length;
11
+ this.mStartPosition = 0;
11
12
  }
12
13
 
13
14
  PDFRStreamForBuffer.prototype.read = function (inAmount) {
@@ -25,7 +26,7 @@ PDFRStreamForBuffer.prototype.notEnded = function () {
25
26
  };
26
27
 
27
28
  PDFRStreamForBuffer.prototype.setPosition = function (inPosition) {
28
- this.rposition = inPosition;
29
+ this.rposition = this.mStartPosition + inPosition;
29
30
  };
30
31
 
31
32
  PDFRStreamForBuffer.prototype.setPositionFromEnd = function (inPosition) {
@@ -37,7 +38,11 @@ PDFRStreamForBuffer.prototype.skip = function (inAmount) {
37
38
  };
38
39
 
39
40
  PDFRStreamForBuffer.prototype.getCurrentPosition = function () {
40
- return this.rposition;
41
+ return this.rposition - this.mStartPosition;
42
+ };
43
+
44
+ PDFRStreamForBuffer.prototype.moveStartPosition = function (inPosition) {
45
+ this.mStartPosition = inPosition;
41
46
  };
42
47
 
43
48
  module.exports = PDFRStreamForBuffer;
@@ -8,6 +8,7 @@ function PDFRStreamForFile(inPath) {
8
8
  this.path = inPath;
9
9
  this.rposition = 0;
10
10
  this.fileSize = fs.statSync(inPath)["size"];
11
+ this.mStartPosition = 0;
11
12
  }
12
13
 
13
14
  PDFRStreamForFile.prototype.read = function (inAmount) {
@@ -25,7 +26,7 @@ PDFRStreamForFile.prototype.notEnded = function () {
25
26
  };
26
27
 
27
28
  PDFRStreamForFile.prototype.setPosition = function (inPosition) {
28
- this.rposition = inPosition;
29
+ this.rposition = this.mStartPosition + inPosition;
29
30
  };
30
31
 
31
32
  PDFRStreamForFile.prototype.setPositionFromEnd = function (inPosition) {
@@ -37,7 +38,11 @@ PDFRStreamForFile.prototype.skip = function (inAmount) {
37
38
  };
38
39
 
39
40
  PDFRStreamForFile.prototype.getCurrentPosition = function () {
40
- return this.rposition;
41
+ return this.rposition - this.mStartPosition;
42
+ };
43
+
44
+ PDFRStreamForFile.prototype.moveStartPosition = function (inPosition) {
45
+ this.mStartPosition = inPosition;
41
46
  };
42
47
 
43
48
  function noop() {}
@@ -252,6 +252,7 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
252
252
  // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
253
253
  // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
254
254
  // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
255
+ // ~0.0.1 --> >=0.0.1 <0.1.0-0
255
256
  const replaceTildes = (comp, options) =>
256
257
  comp.trim().split(/\s+/).map((c) => {
257
258
  return replaceTilde(c, options)
@@ -291,6 +292,8 @@ const replaceTilde = (comp, options) => {
291
292
  // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
292
293
  // ^1.2.3 --> >=1.2.3 <2.0.0-0
293
294
  // ^1.2.0 --> >=1.2.0 <2.0.0-0
295
+ // ^0.0.1 --> >=0.0.1 <0.0.2-0
296
+ // ^0.1.0 --> >=0.1.0 <0.2.0-0
294
297
  const replaceCarets = (comp, options) =>
295
298
  comp.trim().split(/\s+/).map((c) => {
296
299
  return replaceCaret(c, options)
@@ -1,48 +1,88 @@
1
1
  // just pre-load all the stuff that index.js lazily exports
2
2
  const internalRe = require('./internal/re')
3
+ const constants = require('./internal/constants')
4
+ const SemVer = require('./classes/semver')
5
+ const identifiers = require('./internal/identifiers')
6
+ const parse = require('./functions/parse')
7
+ const valid = require('./functions/valid')
8
+ const clean = require('./functions/clean')
9
+ const inc = require('./functions/inc')
10
+ const diff = require('./functions/diff')
11
+ const major = require('./functions/major')
12
+ const minor = require('./functions/minor')
13
+ const patch = require('./functions/patch')
14
+ const prerelease = require('./functions/prerelease')
15
+ const compare = require('./functions/compare')
16
+ const rcompare = require('./functions/rcompare')
17
+ const compareLoose = require('./functions/compare-loose')
18
+ const compareBuild = require('./functions/compare-build')
19
+ const sort = require('./functions/sort')
20
+ const rsort = require('./functions/rsort')
21
+ const gt = require('./functions/gt')
22
+ const lt = require('./functions/lt')
23
+ const eq = require('./functions/eq')
24
+ const neq = require('./functions/neq')
25
+ const gte = require('./functions/gte')
26
+ const lte = require('./functions/lte')
27
+ const cmp = require('./functions/cmp')
28
+ const coerce = require('./functions/coerce')
29
+ const Comparator = require('./classes/comparator')
30
+ const Range = require('./classes/range')
31
+ const satisfies = require('./functions/satisfies')
32
+ const toComparators = require('./ranges/to-comparators')
33
+ const maxSatisfying = require('./ranges/max-satisfying')
34
+ const minSatisfying = require('./ranges/min-satisfying')
35
+ const minVersion = require('./ranges/min-version')
36
+ const validRange = require('./ranges/valid')
37
+ const outside = require('./ranges/outside')
38
+ const gtr = require('./ranges/gtr')
39
+ const ltr = require('./ranges/ltr')
40
+ const intersects = require('./ranges/intersects')
41
+ const simplifyRange = require('./ranges/simplify')
42
+ const subset = require('./ranges/subset')
3
43
  module.exports = {
44
+ parse,
45
+ valid,
46
+ clean,
47
+ inc,
48
+ diff,
49
+ major,
50
+ minor,
51
+ patch,
52
+ prerelease,
53
+ compare,
54
+ rcompare,
55
+ compareLoose,
56
+ compareBuild,
57
+ sort,
58
+ rsort,
59
+ gt,
60
+ lt,
61
+ eq,
62
+ neq,
63
+ gte,
64
+ lte,
65
+ cmp,
66
+ coerce,
67
+ Comparator,
68
+ Range,
69
+ satisfies,
70
+ toComparators,
71
+ maxSatisfying,
72
+ minSatisfying,
73
+ minVersion,
74
+ validRange,
75
+ outside,
76
+ gtr,
77
+ ltr,
78
+ intersects,
79
+ simplifyRange,
80
+ subset,
81
+ SemVer,
4
82
  re: internalRe.re,
5
83
  src: internalRe.src,
6
84
  tokens: internalRe.t,
7
- SEMVER_SPEC_VERSION: require('./internal/constants').SEMVER_SPEC_VERSION,
8
- SemVer: require('./classes/semver'),
9
- compareIdentifiers: require('./internal/identifiers').compareIdentifiers,
10
- rcompareIdentifiers: require('./internal/identifiers').rcompareIdentifiers,
11
- parse: require('./functions/parse'),
12
- valid: require('./functions/valid'),
13
- clean: require('./functions/clean'),
14
- inc: require('./functions/inc'),
15
- diff: require('./functions/diff'),
16
- major: require('./functions/major'),
17
- minor: require('./functions/minor'),
18
- patch: require('./functions/patch'),
19
- prerelease: require('./functions/prerelease'),
20
- compare: require('./functions/compare'),
21
- rcompare: require('./functions/rcompare'),
22
- compareLoose: require('./functions/compare-loose'),
23
- compareBuild: require('./functions/compare-build'),
24
- sort: require('./functions/sort'),
25
- rsort: require('./functions/rsort'),
26
- gt: require('./functions/gt'),
27
- lt: require('./functions/lt'),
28
- eq: require('./functions/eq'),
29
- neq: require('./functions/neq'),
30
- gte: require('./functions/gte'),
31
- lte: require('./functions/lte'),
32
- cmp: require('./functions/cmp'),
33
- coerce: require('./functions/coerce'),
34
- Comparator: require('./classes/comparator'),
35
- Range: require('./classes/range'),
36
- satisfies: require('./functions/satisfies'),
37
- toComparators: require('./ranges/to-comparators'),
38
- maxSatisfying: require('./ranges/max-satisfying'),
39
- minSatisfying: require('./ranges/min-satisfying'),
40
- minVersion: require('./ranges/min-version'),
41
- validRange: require('./ranges/valid'),
42
- outside: require('./ranges/outside'),
43
- gtr: require('./ranges/gtr'),
44
- ltr: require('./ranges/ltr'),
45
- intersects: require('./ranges/intersects'),
46
- simplifyRange: require('./ranges/simplify'),
47
- subset: require('./ranges/subset'),
85
+ SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
86
+ compareIdentifiers: identifiers.compareIdentifiers,
87
+ rcompareIdentifiers: identifiers.rcompareIdentifiers,
48
88
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "_from": "semver@^7.3.5",
3
- "_id": "semver@7.3.7",
3
+ "_id": "semver@7.3.8",
4
4
  "_inBundle": false,
5
- "_integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
5
+ "_integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
6
6
  "_location": "/semver",
7
7
  "_phantomChildren": {},
8
8
  "_requested": {
@@ -18,8 +18,8 @@
18
18
  "_requiredBy": [
19
19
  "/@mapbox/node-pre-gyp"
20
20
  ],
21
- "_resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
22
- "_shasum": "12c5b649afdbf9049707796e22a4028814ce523f",
21
+ "_resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
22
+ "_shasum": "07a78feafb3f7b32347d725e33de7e2a2df67798",
23
23
  "_spec": "semver@^7.3.5",
24
24
  "_where": "/home/runner/work/MuhammaraJS/MuhammaraJS/node_modules/@mapbox/node-pre-gyp",
25
25
  "author": {
@@ -39,7 +39,7 @@
39
39
  "description": "The semantic version parser used by npm.",
40
40
  "devDependencies": {
41
41
  "@npmcli/eslint-config": "^3.0.1",
42
- "@npmcli/template-oss": "3.3.2",
42
+ "@npmcli/template-oss": "4.4.4",
43
43
  "tap": "^16.0.0"
44
44
  },
45
45
  "engines": {
@@ -47,6 +47,7 @@
47
47
  },
48
48
  "files": [
49
49
  "bin/",
50
+ "lib/",
50
51
  "classes/",
51
52
  "functions/",
52
53
  "internal/",
@@ -67,32 +68,33 @@
67
68
  "lint": "eslint \"**/*.js\"",
68
69
  "lintfix": "npm run lint -- --fix",
69
70
  "postlint": "template-oss-check",
70
- "postpublish": "git push origin --follow-tags",
71
71
  "posttest": "npm run lint",
72
- "postversion": "npm publish",
73
- "prepublishOnly": "git push origin --follow-tags",
74
- "preversion": "npm test",
75
72
  "snap": "tap",
76
73
  "template-oss-apply": "template-oss-apply --force",
77
74
  "test": "tap"
78
75
  },
79
76
  "tap": {
80
77
  "check-coverage": true,
81
- "coverage-map": "map.js"
78
+ "coverage-map": "map.js",
79
+ "nyc-arg": [
80
+ "--exclude",
81
+ "tap-snapshots/**"
82
+ ]
82
83
  },
83
84
  "templateOSS": {
84
85
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
85
- "version": "3.3.2",
86
+ "version": "4.4.4",
86
87
  "engines": ">=10",
88
+ "content": "./scripts",
87
89
  "ciVersions": [
88
90
  "10.0.0",
89
91
  "10.x",
90
92
  "12.x",
91
93
  "14.x",
92
- "16.x"
94
+ "16.x",
95
+ "18.x"
93
96
  ],
94
97
  "distPaths": [
95
- "bin/",
96
98
  "classes/",
97
99
  "functions/",
98
100
  "internal/",
@@ -100,7 +102,16 @@
100
102
  "index.js",
101
103
  "preload.js",
102
104
  "range.bnf"
105
+ ],
106
+ "allowPaths": [
107
+ "/classes/",
108
+ "/functions/",
109
+ "/internal/",
110
+ "/ranges/",
111
+ "/index.js",
112
+ "/preload.js",
113
+ "/range.bnf"
103
114
  ]
104
115
  },
105
- "version": "7.3.7"
116
+ "version": "7.3.8"
106
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muhammara",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Create, read and modify PDF files and streams. A drop in replacement for hummusjs PDF library",
5
5
  "homepage": "https://github.com/julianhille/Muhammarajs",
6
6
  "license": "Apache-2.0",
@@ -129,3 +129,18 @@ void ObjectByteReaderWithPosition::Skip(LongBufferSizeType inSkipSize)
129
129
  args[0] = NEW_NUMBER(inSkipSize);
130
130
  func->Call(GET_CURRENT_CONTEXT, OBJECT_FROM_PERSISTENT(mObject), 1, args).ToLocalChecked();
131
131
  }
132
+
133
+ void ObjectByteReaderWithPosition::MoveStartPosition(LongFilePositionType inStartPosition)
134
+ {
135
+ CREATE_ISOLATE_CONTEXT;
136
+ CREATE_ESCAPABLE_SCOPE;
137
+
138
+ Local<Value> value = OBJECT_FROM_PERSISTENT(mObject)->Get(GET_CURRENT_CONTEXT, NEW_STRING("moveStartPosition")).ToLocalChecked();
139
+ if(value->IsUndefined())
140
+ return;
141
+ Local<Function> func = Local<Function>::Cast(value);
142
+
143
+ Local<Value> args[1];
144
+ args[0] = NEW_NUMBER(inStartPosition);
145
+ func->Call(GET_CURRENT_CONTEXT, OBJECT_FROM_PERSISTENT(mObject), 1, args).ToLocalChecked();
146
+ }
@@ -38,6 +38,7 @@ public:
38
38
  virtual void SetPositionFromEnd(LongFilePositionType inOffsetFromEnd);
39
39
  virtual LongFilePositionType GetCurrentPosition();
40
40
  virtual void Skip(LongBufferSizeType inSkipSize);
41
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition);
41
42
 
42
43
 
43
44
  private:
@@ -52,5 +52,9 @@ public:
52
52
  */
53
53
  virtual void Skip(LongBufferSizeType inSkipSize) = 0;
54
54
 
55
+ /*
56
+ Move the start position
57
+ */
58
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition) = 0;
55
59
 
56
60
  };
@@ -50,6 +50,7 @@ void InputBufferedStream::Assign(IByteReaderWithPosition* inReader)
50
50
  {
51
51
  mSourceStream = inReader;
52
52
  mCurrentBufferIndex = mBuffer;
53
+ mStartPosition = 0;
53
54
  }
54
55
 
55
56
  LongBufferSizeType InputBufferedStream::Read(Byte* inBuffer,LongBufferSizeType inBufferSize)
@@ -121,6 +122,7 @@ void InputBufferedStream::Initiate(IByteReaderWithPosition* inSourceReader,IOBas
121
122
  mBuffer = new Byte[mBufferSize];
122
123
  mLastAvailableIndex = mCurrentBufferIndex = mBuffer;
123
124
  mSourceStream = inSourceReader;
125
+ mStartPosition = 0;
124
126
  }
125
127
 
126
128
  void InputBufferedStream::Skip(LongBufferSizeType inSkipSize)
@@ -140,7 +142,7 @@ void InputBufferedStream::Skip(LongBufferSizeType inSkipSize)
140
142
  void InputBufferedStream::SetPosition(LongFilePositionType inOffsetFromStart)
141
143
  {
142
144
  mLastAvailableIndex = mCurrentBufferIndex = mBuffer;
143
- mSourceStream->SetPosition(inOffsetFromStart);
145
+ mSourceStream->SetPosition(mStartPosition + inOffsetFromStart);
144
146
  }
145
147
 
146
148
  void InputBufferedStream::SetPositionFromEnd(LongFilePositionType inOffsetFromEnd)
@@ -158,5 +160,10 @@ LongFilePositionType InputBufferedStream::GetCurrentPosition()
158
160
  {
159
161
  // when reading the current position is the current stream position minus how much is left
160
162
  // to read from the buffer
161
- return mSourceStream->GetCurrentPosition() - (mLastAvailableIndex - mCurrentBufferIndex);
162
- }
163
+ return mSourceStream->GetCurrentPosition() - (mLastAvailableIndex - mCurrentBufferIndex) - mStartPosition;
164
+ }
165
+
166
+ void InputBufferedStream::MoveStartPosition(LongFilePositionType inStartPosition)
167
+ {
168
+ mStartPosition = inStartPosition;
169
+ }
@@ -62,6 +62,7 @@ public:
62
62
  virtual void SetPosition(LongFilePositionType inOffsetFromStart);
63
63
  virtual void SetPositionFromEnd(LongFilePositionType inOffsetFromEnd);
64
64
  virtual LongFilePositionType GetCurrentPosition();
65
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition);
65
66
 
66
67
  IByteReaderWithPosition* GetSourceStream();
67
68
 
@@ -71,6 +72,7 @@ private:
71
72
  IOBasicTypes::Byte* mCurrentBufferIndex;
72
73
  IOBasicTypes::Byte* mLastAvailableIndex;
73
74
  IByteReaderWithPosition* mSourceStream;
75
+ LongFilePositionType mStartPosition;
74
76
 
75
77
  void Initiate(IByteReaderWithPosition* inSourceReader,IOBasicTypes::LongBufferSizeType inBufferSize);
76
78
 
@@ -31,6 +31,7 @@ InputByteArrayStream::InputByteArrayStream(Byte* inByteArray,LongFilePositionTyp
31
31
  mByteArray = inByteArray;
32
32
  mArrayLength = inArrayLength;
33
33
  mCurrentPosition = 0;
34
+ mStartPosition = 0;
34
35
  }
35
36
 
36
37
  InputByteArrayStream::~InputByteArrayStream(void)
@@ -42,6 +43,7 @@ void InputByteArrayStream::Assign(IOBasicTypes::Byte* inByteArray,IOBasicTypes::
42
43
  mByteArray = inByteArray;
43
44
  mArrayLength = inArrayLength;
44
45
  mCurrentPosition = 0;
46
+ mStartPosition = 0;
45
47
  }
46
48
 
47
49
  LongBufferSizeType InputByteArrayStream::Read(IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize)
@@ -73,7 +75,7 @@ void InputByteArrayStream::Skip(LongBufferSizeType inSkipSize)
73
75
 
74
76
  void InputByteArrayStream::SetPosition(LongFilePositionType inOffsetFromStart)
75
77
  {
76
- mCurrentPosition = inOffsetFromStart > mArrayLength ? mArrayLength:inOffsetFromStart;
78
+ mCurrentPosition = inOffsetFromStart > mArrayLength - mStartPosition ? mArrayLength : (mStartPosition + inOffsetFromStart);
77
79
  }
78
80
 
79
81
  void InputByteArrayStream::SetPositionFromEnd(LongFilePositionType inOffsetFromEnd)
@@ -83,5 +85,10 @@ void InputByteArrayStream::SetPositionFromEnd(LongFilePositionType inOffsetFromE
83
85
 
84
86
  LongFilePositionType InputByteArrayStream::GetCurrentPosition()
85
87
  {
86
- return mCurrentPosition;
88
+ return mCurrentPosition - mStartPosition;
89
+ }
90
+
91
+ void InputByteArrayStream::MoveStartPosition(LongFilePositionType inStartPosition)
92
+ {
93
+ mStartPosition = inStartPosition;
87
94
  }
@@ -38,11 +38,13 @@ public:
38
38
  virtual void SetPosition(LongFilePositionType inOffsetFromStart);
39
39
  virtual void SetPositionFromEnd(LongFilePositionType inOffsetFromEnd);
40
40
  virtual LongFilePositionType GetCurrentPosition();
41
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition);
41
42
 
42
43
  private:
43
44
 
44
45
  IOBasicTypes::Byte* mByteArray;
45
46
  LongFilePositionType mArrayLength;
46
47
  LongFilePositionType mCurrentPosition;
48
+ LongFilePositionType mStartPosition;
47
49
 
48
50
  };
@@ -26,6 +26,7 @@ using namespace PDFHummus;
26
26
  InputFileStream::InputFileStream(void)
27
27
  {
28
28
  mStream = NULL;
29
+ mStartPosition = 0;
29
30
  }
30
31
 
31
32
  InputFileStream::~InputFileStream(void)
@@ -39,6 +40,7 @@ InputFileStream::InputFileStream(const std::string& inFilePath)
39
40
  {
40
41
  mStream = NULL;
41
42
  Open(inFilePath);
43
+ mStartPosition = 0;
42
44
  }
43
45
 
44
46
  EStatusCode InputFileStream::Open(const std::string& inFilePath)
@@ -78,13 +80,13 @@ void InputFileStream::Skip(LongBufferSizeType inSkipSize)
78
80
  void InputFileStream::SetPosition(LongFilePositionType inOffsetFromStart)
79
81
  {
80
82
  if(mStream)
81
- SAFE_FSEEK64(mStream,inOffsetFromStart,SEEK_SET);
83
+ SAFE_FSEEK64(mStream,mStartPosition + inOffsetFromStart,SEEK_SET);
82
84
  }
83
85
 
84
86
  LongFilePositionType InputFileStream::GetCurrentPosition()
85
87
  {
86
88
  if(mStream)
87
- return SAFE_FTELL64(mStream);
89
+ return SAFE_FTELL64(mStream) - mStartPosition;
88
90
  else
89
91
  return 0;
90
92
  }
@@ -115,3 +117,8 @@ void InputFileStream::SetPositionFromEnd(LongFilePositionType inOffsetFromEnd)
115
117
  SAFE_FSEEK64(mStream,0,SEEK_SET);
116
118
  }
117
119
  }
120
+
121
+ void InputFileStream::MoveStartPosition(LongFilePositionType inStartPosition)
122
+ {
123
+ mStartPosition = inStartPosition;
124
+ }
@@ -50,10 +50,12 @@ public:
50
50
  virtual void SetPosition(LongFilePositionType inOffsetFromStart);
51
51
  virtual void SetPositionFromEnd(LongFilePositionType inOffsetFromEnd);
52
52
  virtual LongFilePositionType GetCurrentPosition();
53
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition);
53
54
 
54
55
  LongFilePositionType GetFileSize();
55
56
 
56
57
  private:
57
58
 
58
59
  FILE* mStream;
60
+ LongFilePositionType mStartPosition;
59
61
  };
@@ -24,11 +24,13 @@
24
24
  InputStringBufferStream::InputStringBufferStream(MyStringBuf* inBufferToReadFrom)
25
25
  {
26
26
  mBufferToReadFrom = inBufferToReadFrom;
27
+ mStartPosition = 0;
27
28
  }
28
29
 
29
30
  void InputStringBufferStream::Assign(MyStringBuf* inBufferToReadFrom)
30
31
  {
31
32
  mBufferToReadFrom = inBufferToReadFrom;
33
+ mStartPosition = 0;
32
34
  }
33
35
 
34
36
  InputStringBufferStream::~InputStringBufferStream(void)
@@ -52,7 +54,7 @@ void InputStringBufferStream::Skip(LongBufferSizeType inSkipSize)
52
54
 
53
55
  void InputStringBufferStream::SetPosition(LongFilePositionType inOffsetFromStart)
54
56
  {
55
- mBufferToReadFrom->pubseekoff((long)inOffsetFromStart,std::ios_base::beg);
57
+ mBufferToReadFrom->pubseekoff((long)mStartPosition + (long)inOffsetFromStart,std::ios_base::beg);
56
58
  }
57
59
 
58
60
  void InputStringBufferStream::SetPositionFromEnd(LongFilePositionType inOffsetFromEnd)
@@ -63,5 +65,10 @@ void InputStringBufferStream::SetPositionFromEnd(LongFilePositionType inOffsetFr
63
65
 
64
66
  LongFilePositionType InputStringBufferStream::GetCurrentPosition()
65
67
  {
66
- return mBufferToReadFrom->GetCurrentReadPosition();
67
- }
68
+ return mBufferToReadFrom->GetCurrentReadPosition() - mStartPosition;
69
+ }
70
+
71
+ void InputStringBufferStream::MoveStartPosition(LongFilePositionType inStartPosition)
72
+ {
73
+ mStartPosition = inStartPosition;
74
+ }
@@ -43,9 +43,11 @@ public:
43
43
  virtual void SetPosition(LongFilePositionType inOffsetFromStart);
44
44
  virtual void SetPositionFromEnd(LongFilePositionType inOffsetFromEnd);
45
45
  virtual LongFilePositionType GetCurrentPosition();
46
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition);
46
47
 
47
48
  private:
48
49
  MyStringBuf* mBufferToReadFrom;
50
+ LongFilePositionType mStartPosition;
49
51
 
50
52
 
51
53
  };
@@ -32,6 +32,7 @@ InputStringStream::InputStringStream(const string& inString)
32
32
  mStartPosition = inString.begin();
33
33
  mEndPosition = inString.end();
34
34
  mCurrentPosition = mStartPosition;
35
+ mString = inString;
35
36
  }
36
37
 
37
38
  InputStringStream::~InputStringStream(void)
@@ -43,6 +44,7 @@ void InputStringStream::Assign(const string& inString)
43
44
  mStartPosition = inString.begin();
44
45
  mEndPosition = inString.end();
45
46
  mCurrentPosition = mStartPosition;
47
+ mString = inString;
46
48
  }
47
49
 
48
50
  LongBufferSizeType InputStringStream::Read(Byte* inBuffer, LongBufferSizeType inBufferSize)
@@ -79,3 +81,8 @@ LongFilePositionType InputStringStream::GetCurrentPosition()
79
81
  {
80
82
  return mCurrentPosition - mStartPosition;
81
83
  }
84
+
85
+ void InputStringStream::MoveStartPosition(LongFilePositionType inStartPosition)
86
+ {
87
+ mStartPosition = mString.begin() + (string::size_type)inStartPosition;
88
+ }
@@ -40,11 +40,13 @@ public:
40
40
  virtual void SetPosition(LongFilePositionType inOffsetFromStart);
41
41
  virtual void SetPositionFromEnd(LongFilePositionType inOffsetFromEnd);
42
42
  virtual LongFilePositionType GetCurrentPosition();
43
+ virtual void MoveStartPosition(LongFilePositionType inStartPosition);
43
44
 
44
45
  private:
45
46
 
46
47
  std::string::const_iterator mStartPosition;
47
48
  std::string::const_iterator mEndPosition;
48
49
  std::string::const_iterator mCurrentPosition;
50
+ std::string mString;
49
51
 
50
52
  };
@@ -98,7 +98,7 @@ PDFObject* PDFObjectParser::ParseNewObject()
98
98
  if(!GetNextToken(token))
99
99
  break;
100
100
 
101
- // based on the parsed token, and parhaps some more, determine the type of object
101
+ // based on the parsed token, and perhaps some more, determine the type of object
102
102
  // and how to parse it.
103
103
 
104
104
  // Boolean
@@ -166,14 +166,20 @@ EStatusCode PDFParser::ParseHeaderLine()
166
166
  return PDFHummus::eFailure;
167
167
  }
168
168
 
169
- if(tokenizerResult.second.compare(0,scPDFMagic.size(),scPDFMagic) != 0)
169
+ do
170
170
  {
171
- TRACE_LOG1("PDFParser::ParseHeaderLine, file does not begin as a PDF file. a PDF file should start with \"%%PDF-\". file header = %s",tokenizerResult.second.substr(0, MAX_TRACE_SIZE - 200).c_str());
172
- return PDFHummus::eFailure;
173
- }
171
+ if(tokenizerResult.second.compare(0,scPDFMagic.size(),scPDFMagic) == 0)
172
+ {
173
+ mPDFLevel = Double(tokenizerResult.second.substr(scPDFMagic.size()));
174
+ mStream->MoveStartPosition(mStream->GetCurrentPosition() - tokenizerResult.second.size() - 1);
175
+ return PDFHummus::eSuccess;
176
+ }
174
177
 
175
- mPDFLevel = Double(tokenizerResult.second.substr(scPDFMagic.size()));
176
- return PDFHummus::eSuccess;
178
+ tokenizerResult = tokenizer.GetNextToken();
179
+ } while (tokenizerResult.first && mStream->GetCurrentPosition() < 1024);
180
+
181
+ TRACE_LOG("PDFParser::ParseHeaderLine, file does not begin as a PDF file. a PDF file should contain \"%%PDF-\" within the first 1024 bytes.");
182
+ return PDFHummus::eFailure;
177
183
  }
178
184
 
179
185
  static const std::string scEOF = "%%EOF";
@@ -352,6 +358,12 @@ EStatusCode PDFParser::ParseLastXrefPosition()
352
358
  mObjectParser.ResetReadState();
353
359
  RefCountPtr<PDFObject> anObject(mObjectParser.ParseNewObject());
354
360
 
361
+ if (!anObject) {
362
+ status = PDFHummus::eFailure;
363
+ TRACE_LOG("PDFParser::ParseXrefPosition: Unable to find any object");
364
+ break;
365
+ }
366
+
355
367
  if(anObject->GetType() == PDFObject::ePDFObjectInteger)
356
368
  {
357
369
  mLastXrefPosition = (LongFilePositionType)((PDFInteger*)anObject.GetPtr())->GetValue();