forked from NITJSR-OSS/PDF-Thumbnail-Creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfr-stream-for-buffer.js
46 lines (34 loc) · 994 Bytes
/
pdfr-stream-for-buffer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// https://stackoverflow.com/questions/42512982/node-js-get-the-first-page-of-pdf-buffer => getting buffer array for the first page
'use strict';
// const EventEmitter = require('events');
class PDFRStreamForBuffer {
constructor(buffer) {
this.innerBuffer = buffer;
this.rposition = 0;
this.fileSize = buffer.byteLength;
}
read(inAmount) {
let arr = [];
for (let i = 0; i < inAmount; i++) {
arr.push(this.innerBuffer[this.rposition + i]);
}
this.rposition += inAmount;
return arr;
}
notEnded() {
return this.rposition < this.fileSize;
}
setPosition(inPosition) {
this.rposition = inPosition;
}
setPositionFromEnd(inPosition) {
this.rposition = this.fileSize - inPosition;
}
skip(inAmount) {
this.rposition += inAmount;
}
getCurrentPosition() {
return this.rposition;
}
}
module.exports = PDFRStreamForBuffer;