Compare commits

..

No commits in common. "8f4c0169a0f82423fedb77fb7c28503e52a93419" and "cd4a30341f048d722e06d078a94911cc19bfc3a6" have entirely different histories.

2 changed files with 16 additions and 26 deletions

View File

@ -168,30 +168,28 @@ function writeInt(number, size, offset, buffer) {
}
function writeString(string, offset, buffer) {
const ii = string.length;
for (let i = 0; i < ii; i++) {
for (let i = 0, len = string.length; i < len; 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(),
...Object.values(xrefInfo.info),
];
const md5BufferLen = md5Buffer.reduce((a, str) => a + str.length, 0);
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 array = new Uint8Array(md5BufferLen);
let offset = 0;
for (const str of md5Buffer) {
offset = writeString(str, offset, array);
writeString(str, offset, array);
offset += str.length;
}
return bytesToString(calculateMD5(array, 0, array.length));
return bytesToString(calculateMD5(array));
}
function writeXFADataForAcroform(str, changes) {
@ -479,7 +477,8 @@ async function incrementalUpdate({
// New data
for (const str of buffer) {
offset = writeString(str, offset, array);
writeString(str, offset, array);
offset += str.length;
}
return array;

View File

@ -19,15 +19,6 @@ 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();
@ -59,7 +50,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) (\xeb\x4b\x2a\xe7\x31\x36\xf0\xcd\x83\x35\x94\x2a\x36\xcf\xaa\xb0)] " +
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
"/Length 9>> stream\n" +
"\x01\x01\x2d" +
"\x01\x05\x4e" +
@ -92,7 +83,7 @@ describe("Writer", function () {
"0000000010 00000 n\r\n" +
"trailer\n" +
"<< /Prev 314 /Size 789 " +
"/ID [(id) (\xeb\x4b\x2a\xe7\x31\x36\xf0\xcd\x83\x35\x94\x2a\x36\xcf\xaa\xb0)]>>\n" +
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
"startxref\n" +
"10\n" +
"%%EOF\n";
@ -288,7 +279,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) (\x5f\xd1\x43\x8e\xf8\x62\x79\x80\xbb\xd6\xf7\xb6\xd2\xb5\x6f\xd8)] " +
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
"/Length 9>> stream\n" +
"\x00\x00\x2e" +
"\x01\x01\x4e" +
@ -320,7 +311,7 @@ describe("Writer", function () {
"0000000005 00000 n\r\n" +
"trailer\n" +
"<< /Prev 314 /Size 789 " +
"/ID [(id) (\x5f\xd1\x43\x8e\xf8\x62\x79\x80\xbb\xd6\xf7\xb6\xd2\xb5\x6f\xd8)]>>\n" +
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
"startxref\n" +
"5\n" +
"%%EOF\n";