diff --git a/bin/cmd.js b/bin/cmd.js index 4e22cf1..db9217a 100644 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -35,15 +35,15 @@ function parseSinkType(sinkType) { const program = new Command(); -/* program .command('test') .argument('', 'test upload buffer size, e.g. 1024 / 42K / 2M', String) .argument('', 'chunk size, e.g. 1024 / 42K / 2M', String) .option('-s, --sinkType ', 'use only this kind of sink', "bili") .option('-c, --concurrency ', 'concurrency', "1") + .option('-i, --interval ', 'interval', "200") .option('-m, --maskPhotoFilePath ', 'maskPhotoFilePath', String) - .option('-u, --usedBits ', 'usedBist', String) + .option('-b, --usedBits ', 'usedBits', String) .option('--no-validate', 'do not do validation') .action(async (size, chunkSize, options) => { const sinkType = parseSinkType(options.sinkType); @@ -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') @@ -72,18 +72,18 @@ program .option('-c, --concurrency ', 'concurrency', "1") .option('-i, --interval ', 'interval', "200") .option('-m, --maskPhotoFilePath ', 'maskPhotoFilePath', String) - .option('--no-validate', 'do not do validation') + .option('-b, --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)); diff --git a/src/jpeg-encoder/index.ts b/src/jpeg-encoder/index.ts index 1980a0f..18ea52f 100644 --- a/src/jpeg-encoder/index.ts +++ b/src/jpeg-encoder/index.ts @@ -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; diff --git a/src/sinks/base.ts b/src/sinks/base.ts index d1beeed..0600d2f 100644 --- a/src/sinks/base.ts +++ b/src/sinks/base.ts @@ -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; } @@ -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) { diff --git a/src/sinks/index.ts b/src/sinks/index.ts index 79460e8..c1bb8a4 100644 --- a/src/sinks/index.ts +++ b/src/sinks/index.ts @@ -67,6 +67,7 @@ class SinkDelegate { hash.update(buf); return { sink: sink, + original: buf, encoded: encoded, index: index, originalLength: buf.byteLength, @@ -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); }