Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/platform/wasm/examples/streams/custom-stream.js @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 "use strict" | |
| 2 | |
| 3 import * as fs from "fs" | |
| 4 import * as mupdf from "mupdf" | |
| 5 | |
| 6 // Use synchronous file descriptor API with Node. | |
| 7 class NodeFileStream { | |
| 8 constructor(path) { | |
| 9 this.fd = fs.openSync(path) | |
| 10 } | |
| 11 fileSize() { | |
| 12 return fs.fstatSync(this.fd).size | |
| 13 } | |
| 14 read(memory, offset, size, position) { | |
| 15 return fs.readSync(this.fd, memory, offset, size, position) | |
| 16 } | |
| 17 close() { | |
| 18 fs.closeSync(this.fd) | |
| 19 } | |
| 20 } | |
| 21 | |
| 22 // Use FileReaderSync on Blob/File objects in Web Workers. | |
| 23 class WorkerBlobStream { | |
| 24 constructor(blob) { | |
| 25 this.reader = new FileReaderSync() | |
| 26 this.blob = blob | |
| 27 } | |
| 28 fileSize() { | |
| 29 return this.blob.size | |
| 30 } | |
| 31 read(memory, offset, size, position) { | |
| 32 var data = this.reader.readAsArrayBuffer(this.blob.slice(position, position + size)) | |
| 33 memory.set(new Uint8Array(data), offset) | |
| 34 return data.byteLength | |
| 35 } | |
| 36 close() { | |
| 37 this.reader = null | |
| 38 this.blob = null | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 /* to test: | |
| 43 var stm = new mupdf.Stream(new NodeFileStream("pdfref17.pdf")) | |
| 44 var doc = mupdf.Document.openDocument(stm, "application/pdf") | |
| 45 */ |
