Skip to content

Commit

Permalink
Proper name
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 20, 2024
1 parent 090e6c1 commit 966083d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions bin/download-flash-cn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {walk} from '../util/util.mjs';
import {queue} from '../util/queue.mjs';
import {download} from '../util/download.mjs';
import {Hasher, Counter, Void} from '../util/stream.mjs';
import {Crc64} from '../util/crc64.mjs';
import {Crc64xz} from '../util/crc64xz.mjs';
import {
createPackageUrl,
groupFilesCaching,
Expand Down Expand Up @@ -74,17 +74,18 @@ async function main() {
new Void()
);
} else {
const hashCrc64 = new Crc64();
let crc64ecma = null;
const hashCrc64xz = new Crc64xz();
let crc64xz = null;
await mkdir(fileDir, {recursive: true});
await download(filePart, `${source}?_=${Date.now()}`, {
headers: {
'User-Agent': userAgent,
Referer: referer
},
transforms: [new Hasher([hashCrc64]), hasher],
transforms: [new Hasher([hashCrc64xz]), hasher],
response(response) {
crc64ecma = response.headers.get('x-cos-hash-crc64ecma');
// Wrong name, common mistake.
crc64xz = response.headers.get('x-cos-hash-crc64ecma');
const ct = response.headers.get('content-type');
if (ct !== mimetype) {
throw new Error(
Expand All @@ -97,10 +98,10 @@ async function main() {
}
});

// Validate crc64ecma hash header.
const crc64 = hashCrc64.digest().readBigUint64BE().toString();
if (crc64 !== crc64ecma) {
throw new Error(`CRC64 header: ${crc64} !== ${crc64ecma}`);
// Validate crc64 hash header.
const crc64 = hashCrc64xz.digest().readBigUint64BE().toString();
if (crc64 !== crc64xz) {
throw new Error(`CRC64 header: ${crc64} !== ${crc64xz}`);
}

st = await stat(filePart);
Expand Down
2 changes: 1 addition & 1 deletion util/crc64.mjs → util/crc64xz.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createTable() {

let TABLE;

export class Crc64 extends Writable {
export class Crc64xz extends Writable {
constructor() {
super();

Expand Down

0 comments on commit 966083d

Please sign in to comment.