mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-11 09:35:49 +02:00
Compare commits
4 Commits
cd4a30341f
...
8f4c0169a0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f4c0169a0 | ||
|
|
50eb97afb3 | ||
|
|
a229914b46 | ||
|
|
e6c869c127 |
@ -168,28 +168,30 @@ function writeInt(number, size, offset, buffer) {
|
||||
}
|
||||
|
||||
function writeString(string, offset, buffer) {
|
||||
for (let i = 0, len = string.length; i < len; i++) {
|
||||
const ii = string.length;
|
||||
for (let i = 0; i < ii; i++) {
|
||||
buffer[offset + i] = string.charCodeAt(i) & 0xff;
|
||||
}
|
||||
return offset + ii;
|
||||
}
|
||||
|
||||
function computeMD5(filesize, xrefInfo) {
|
||||
const time = Math.floor(Date.now() / 1000);
|
||||
const filename = xrefInfo.filename || "";
|
||||
const md5Buffer = [time.toString(), filename, filesize.toString()];
|
||||
let md5BufferLen = md5Buffer.reduce((a, str) => a + str.length, 0);
|
||||
for (const value of Object.values(xrefInfo.info)) {
|
||||
md5Buffer.push(value);
|
||||
md5BufferLen += value.length;
|
||||
}
|
||||
const md5Buffer = [
|
||||
time.toString(),
|
||||
filename,
|
||||
filesize.toString(),
|
||||
...Object.values(xrefInfo.info),
|
||||
];
|
||||
const md5BufferLen = md5Buffer.reduce((a, str) => a + str.length, 0);
|
||||
|
||||
const array = new Uint8Array(md5BufferLen);
|
||||
let offset = 0;
|
||||
for (const str of md5Buffer) {
|
||||
writeString(str, offset, array);
|
||||
offset += str.length;
|
||||
offset = writeString(str, offset, array);
|
||||
}
|
||||
return bytesToString(calculateMD5(array));
|
||||
return bytesToString(calculateMD5(array, 0, array.length));
|
||||
}
|
||||
|
||||
function writeXFADataForAcroform(str, changes) {
|
||||
@ -477,8 +479,7 @@ async function incrementalUpdate({
|
||||
|
||||
// New data
|
||||
for (const str of buffer) {
|
||||
writeString(str, offset, array);
|
||||
offset += str.length;
|
||||
offset = writeString(str, offset, array);
|
||||
}
|
||||
|
||||
return array;
|
||||
|
||||
@ -19,6 +19,15 @@ import { bytesToString } from "../../src/shared/util.js";
|
||||
import { StringStream } from "../../src/core/stream.js";
|
||||
|
||||
describe("Writer", function () {
|
||||
beforeAll(function () {
|
||||
jasmine.clock().install();
|
||||
jasmine.clock().mockDate(new Date(0));
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
describe("Incremental update", function () {
|
||||
it("should update a file with new objects", async function () {
|
||||
const originalData = new Uint8Array();
|
||||
@ -50,7 +59,7 @@ describe("Writer", function () {
|
||||
"defg\n" +
|
||||
"789 0 obj\n" +
|
||||
"<< /Prev 314 /Size 790 /Type /XRef /Index [123 1 456 1 789 1] " +
|
||||
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
|
||||
"/W [1 1 1] /ID [(id) (\xeb\x4b\x2a\xe7\x31\x36\xf0\xcd\x83\x35\x94\x2a\x36\xcf\xaa\xb0)] " +
|
||||
"/Length 9>> stream\n" +
|
||||
"\x01\x01\x2d" +
|
||||
"\x01\x05\x4e" +
|
||||
@ -83,7 +92,7 @@ describe("Writer", function () {
|
||||
"0000000010 00000 n\r\n" +
|
||||
"trailer\n" +
|
||||
"<< /Prev 314 /Size 789 " +
|
||||
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
|
||||
"/ID [(id) (\xeb\x4b\x2a\xe7\x31\x36\xf0\xcd\x83\x35\x94\x2a\x36\xcf\xaa\xb0)]>>\n" +
|
||||
"startxref\n" +
|
||||
"10\n" +
|
||||
"%%EOF\n";
|
||||
@ -279,7 +288,7 @@ describe("Writer", function () {
|
||||
"\nabc\n" +
|
||||
"789 0 obj\n" +
|
||||
"<< /Prev 314 /Size 790 /Type /XRef /Index [123 1 456 1 789 1] " +
|
||||
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
|
||||
"/W [1 1 1] /ID [(id) (\x5f\xd1\x43\x8e\xf8\x62\x79\x80\xbb\xd6\xf7\xb6\xd2\xb5\x6f\xd8)] " +
|
||||
"/Length 9>> stream\n" +
|
||||
"\x00\x00\x2e" +
|
||||
"\x01\x01\x4e" +
|
||||
@ -311,7 +320,7 @@ describe("Writer", function () {
|
||||
"0000000005 00000 n\r\n" +
|
||||
"trailer\n" +
|
||||
"<< /Prev 314 /Size 789 " +
|
||||
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
|
||||
"/ID [(id) (\x5f\xd1\x43\x8e\xf8\x62\x79\x80\xbb\xd6\xf7\xb6\xd2\xb5\x6f\xd8)]>>\n" +
|
||||
"startxref\n" +
|
||||
"5\n" +
|
||||
"%%EOF\n";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user