MCPcopy
hub / github.com/diegomura/react-pdf / open

Method open

packages/pdfkit/src/image.js:7–30  ·  view source on GitHub ↗
(src, label)

Source from the content-addressed store, hash-verified

5
6class PDFImage {
7 static open(src, label) {
8 let data;
9 if (Buffer.isBuffer(src)) {
10 data = src;
11 } else if (src instanceof ArrayBuffer) {
12 data = Buffer.from(new Uint8Array(src));
13 } else {
14 let match = /^data:.+;base64,(.*)$/.exec(src);
15 if (match) {
16 data = Buffer.from(match[1], 'base64');
17 } else if (!BROWSER) {
18 data = fs.readFileSync(src);
19 if (!data) return;
20 }
21 }
22
23 if (data[0] === 0xff && data[1] === 0xd8) {
24 return new JPEG(data, label);
25 } else if (data[0] === 0x89 && data.toString('ascii', 1, 4) === 'PNG') {
26 return new PNG(data, label);
27 } else {
28 throw new Error('Unknown image format.');
29 }
30 }
31}
32
33export default PDFImage;

Callers

nothing calls this directly

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected