Skip to content

Commit

Permalink
Add validation for test cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
buptsb committed Jan 8, 2024
1 parent 9766abb commit 0a70d5b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
14 changes: 7 additions & 7 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ function parseSinkType(sinkType) {

const program = new Command();

/*
program
.command('test')
.argument('<size>', 'test upload buffer size, e.g. 1024 / 42K / 2M', String)
.argument('<chunkSize>', 'chunk size, e.g. 1024 / 42K / 2M', String)
.option('-s, --sinkType <sinkType>', 'use only this kind of sink', "bili")
.option('-c, --concurrency <concurrency>', 'concurrency', "1")
.option('-i, --interval <sleep_interval>', 'interval', "200")
.option('-m, --maskPhotoFilePath <maskPhotoFilePath>', 'maskPhotoFilePath', String)
.option('-u, --usedBits <usedBist>', 'usedBist', String)
.option('-b, --usedBits <usedBits>', 'usedBits', String)
.option('--no-validate', 'do not do validation')
.action(async (size, chunkSize, options) => {
const sinkType = parseSinkType(options.sinkType);
Expand All @@ -54,15 +54,15 @@ program
filePath,
parseChunkSize(chunkSize),
parseInt(options.concurrency),
options.validate !== false,
options.validate,
memfs,
sinkType,
options.maskPhotoFilePath,
options.usedBits,
parseInt(options.interval),
);
console.log(await f.GenerateDescription());
});
*/

program
.command('upload')
Expand All @@ -72,18 +72,18 @@ program
.option('-c, --concurrency <concurrency>', 'concurrency', "1")
.option('-i, --interval <sleep_interval>', 'interval', "200")
.option('-m, --maskPhotoFilePath <maskPhotoFilePath>', 'maskPhotoFilePath', String)
.option('--no-validate', 'do not do validation')
.option('-b, --usedBits <usedBits>', 'usedBits', "")
.action(async (filePath, chunkSize, options) => {
const sinkType = parseSinkType(options.sinkType);
const f = new UploadFile(
filePath,
parseChunkSize(chunkSize),
parseInt(options.concurrency),
options.validate !== false,
false,
fs,
sinkType,
options.maskPhotoFilePath,
"",
options.usedBits,
parseInt(options.interval),
);
console.log(await f.GenerateDescription(true));
Expand Down
2 changes: 1 addition & 1 deletion src/jpeg-encoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class JpegEncoder extends JpegChannel {
// to output image's most significant bits.
if (nextPhotoMaskByteFn) {
assert(this.usedBits.from >= 2,
"When using photo mask, usedBits' from bit index should be greater than 1.")
"When using photo mask, usedBits's from bit index should be greater than 1.")
const photoMask = nextPhotoMaskByteFn(width);
const usedMask = keepMostSignificantNBits(photoMask, this.usedBits.from - 1);
nextByte |= usedMask;
Expand Down
11 changes: 1 addition & 10 deletions src/sinks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ export class BasicSink {
config.maskPhotoFilePath,
);
const url = await this.DoUpload(encoded as ArrayBuffer, config);
if (config.validate) {
const err = await this.validate(original, url, config.toDownloadConfig());
if (err) {
throw err;
}
}
return url;
}

Expand Down Expand Up @@ -65,12 +59,9 @@ export class BasicSink {
const decoded = await this.DownloadDecodeDecrypt(url, original.byteLength, config);
for (let i = 0; i < original.byteLength; i++) {
if (original[i] !== decoded[i]) {
console.log("mismatch", original, url, decoded)
return new Error(`Mismatch at index ${i}: ${original[i]} : ${decoded[i]}`);
throw new Error(`Mismatch at index ${i}: ${original[i]} : ${decoded[i]}`);
}
}
console.log(`Validate ${url} successfully.`)
return null;
}

match(url: string) {
Expand Down
4 changes: 4 additions & 0 deletions src/sinks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SinkDelegate {
hash.update(buf);
return {
sink: sink,
original: buf,
encoded: encoded,
index: index,
originalLength: buf.byteLength,
Expand All @@ -76,6 +77,9 @@ class SinkDelegate {
}),
task.createLimitedTasklet(async (params) => {
const urlString = await params.sink.DoUpload(params.encoded, config);
if (config.validate) {
await params.sink.validate(params.original, urlString, usedConfig.toDownloadConfig());
}
if (config.sleepInterval > 0) {
await sleep(config.sleepInterval);
}
Expand Down

0 comments on commit 0a70d5b

Please sign in to comment.