• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adnsistemas / pdf-lib / #18

24 Mar 2026 08:15PM UTC coverage: 74.286% (+0.3%) from 74.001%
#18

push

David N. Abdala
Documentation change

2569 of 3981 branches covered (64.53%)

Branch coverage included in aggregate %.

7372 of 9401 relevant lines covered (78.42%)

297170.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.2
/src/core/objects/PDFStream.ts
1
import { MethodNotImplementedError } from '../errors';
54✔
2
import PDFDict from './PDFDict';
3
import PDFName from './PDFName';
54✔
4
import PDFNumber from './PDFNumber';
54✔
5
import PDFObject from './PDFObject';
54✔
6
import PDFContext from '../PDFContext';
7
import CharCodes from '../syntax/CharCodes';
54✔
8
import { PDFClasses } from '../../api/objects';
54✔
9

10
class PDFStream extends PDFObject {
11
  static className = () => PDFClasses.PDFStream;
373,236✔
12
  myClass(): PDFClasses {
13
    return PDFClasses.PDFStream;
83✔
14
  }
15
  readonly dict: PDFDict;
16

17
  constructor(dict: PDFDict) {
18
    super();
28,108✔
19
    this.dict = dict;
28,108✔
20
  }
21

22
  clone(_context?: PDFContext): PDFStream {
23
    throw new MethodNotImplementedError(this.constructor.name, 'clone');
×
24
  }
25

26
  getContentsString(): string {
27
    throw new MethodNotImplementedError(
×
28
      this.constructor.name,
29
      'getContentsString',
30
    );
31
  }
32

33
  getContents(): Uint8Array {
34
    throw new MethodNotImplementedError(this.constructor.name, 'getContents');
×
35
  }
36

37
  getContentsSize(): number {
38
    throw new MethodNotImplementedError(
×
39
      this.constructor.name,
40
      'getContentsSize',
41
    );
42
  }
43

44
  updateContents(_contents: Uint8Array): void {
45
    throw new MethodNotImplementedError(
×
46
      this.constructor.name,
47
      'updateContents',
48
    );
49
  }
50

51
  updateDict(): void {
52
    const contentsSize = this.getContentsSize();
2,102✔
53
    this.dict.set(PDFName.Length, PDFNumber.of(contentsSize));
2,102✔
54
  }
55

56
  sizeInBytes(): number {
57
    this.updateDict();
1,043✔
58
    return this.dict.sizeInBytes() + this.getContentsSize() + 18;
1,043✔
59
  }
60

61
  toString(): string {
62
    this.updateDict();
19✔
63
    let streamString = this.dict.toString();
19✔
64
    streamString += '\nstream\n';
19✔
65
    streamString += this.getContentsString();
19✔
66
    streamString += '\nendstream';
19✔
67
    return streamString;
19✔
68
  }
69

70
  copyBytesInto(buffer: Uint8Array, offset: number): number {
71
    this.updateDict();
1,039✔
72
    const initialOffset = offset;
1,039✔
73

74
    offset += this.dict.copyBytesInto(buffer, offset);
1,039✔
75
    buffer[offset++] = CharCodes.Newline;
1,039✔
76

77
    buffer[offset++] = CharCodes.s;
1,039✔
78
    buffer[offset++] = CharCodes.t;
1,039✔
79
    buffer[offset++] = CharCodes.r;
1,039✔
80
    buffer[offset++] = CharCodes.e;
1,039✔
81
    buffer[offset++] = CharCodes.a;
1,039✔
82
    buffer[offset++] = CharCodes.m;
1,039✔
83
    buffer[offset++] = CharCodes.Newline;
1,039✔
84

85
    const contents = this.getContents();
1,039✔
86
    for (let idx = 0, len = contents.length; idx < len; idx++) {
1,039✔
87
      buffer[offset++] = contents[idx];
2,962,770✔
88
    }
89

90
    buffer[offset++] = CharCodes.Newline;
1,039✔
91
    buffer[offset++] = CharCodes.e;
1,039✔
92
    buffer[offset++] = CharCodes.n;
1,039✔
93
    buffer[offset++] = CharCodes.d;
1,039✔
94
    buffer[offset++] = CharCodes.s;
1,039✔
95
    buffer[offset++] = CharCodes.t;
1,039✔
96
    buffer[offset++] = CharCodes.r;
1,039✔
97
    buffer[offset++] = CharCodes.e;
1,039✔
98
    buffer[offset++] = CharCodes.a;
1,039✔
99
    buffer[offset++] = CharCodes.m;
1,039✔
100

101
    return offset - initialOffset;
1,039✔
102
  }
103
}
104

105
export default PDFStream;
54✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc