🐛 Allow for 256kb piece lengths

This commit is contained in:
C-3PO 2018-07-05 02:09:26 +02:00
parent 58963160c2
commit 397e1fd172
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
4 changed files with 9 additions and 9 deletions

View file

@ -1,6 +1,6 @@
export default function failWithError(usage: string, msg?: string) { export default function failWithError(usage: string, msg?: string) {
if (msg !== undefined) { if (msg !== undefined) {
process.stderr.write(`${msg.trim()}\n`); process.stderr.write(`Error: ${msg.trim()}\n`);
} }
process.stderr.write(`Usage: ${usage} \n`); process.stderr.write(`Usage: ${usage} \n`);
process.exit(1); process.exit(1);

View file

@ -7,13 +7,13 @@ import verifyProductName from './ssn/verify/verifyProductName';
const failFunction = failWithError.bind(null, 'node dist/getManifest.js <product>'); const failFunction = failWithError.bind(null, 'node dist/getManifest.js <product>');
if (process.argv.length !== 3) { if (process.argv.length !== 3) {
failFunction(`Error: Expected 1 argument but ${process.argv.length - 2} arguments were supplied.`); failFunction(`Expected 1 argument but ${process.argv.length - 2} arguments were supplied.`);
} }
//Check that product name is valid //Check that product name is valid
const product = process.argv[2]; const product = process.argv[2];
if (!verifyProductName(product)) { if (!verifyProductName(product)) {
failFunction(`Error: "${product} is not a valid product name.`); failFunction(`"${product} is not a valid product name.`);
} }
//Get manifest and write output to console //Get manifest and write output to console

View file

@ -7,23 +7,23 @@ import verifyProductName from './ssn/verify/verifyProductName';
const failFunction = failWithError.bind(null, 'node dist/getSolidpkg.js <product> <from> <to>'); const failFunction = failWithError.bind(null, 'node dist/getSolidpkg.js <product> <from> <to>');
if (process.argv.length !== 5) { if (process.argv.length !== 5) {
failFunction(`Error: Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`); failFunction(`Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`);
} }
//Check that product name is valid //Check that product name is valid
const product = process.argv[2]; const product = process.argv[2];
if (!verifyProductName(product)) { if (!verifyProductName(product)) {
failFunction(`Error: "${product.substring(0, 300)}" is not a valid product name.`); failFunction(`"${product.substring(0, 300)}" is not a valid product name.`);
} }
//Check that from and to are valid numbers //Check that from and to are valid numbers
const from = process.argv[3]; const from = process.argv[3];
const to = process.argv[4]; const to = process.argv[4];
if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) { if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) {
failFunction(`Error: from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`); failFunction(`from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`);
} }
if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) { if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) {
failFunction(`Error: to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`); failFunction(`to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`);
} }
//Get solidpkg and write output to console //Get solidpkg and write output to console

View file

@ -53,8 +53,8 @@ export default function verifySolidpkg(file: ISolid, { product, from, to }: {pro
} }
} }
if (!([0x1_0000, 0x8_0000, 0x40_0000]).includes(file.info['piece length'])) { if (!([0x1_0000, 0x4_0000, 0x8_0000, 0x40_0000]).includes(file.info['piece length'])) {
throw new Error(`Expected piece length to be "65536", "524288" or "4194304" but it was "${file.info['piece length']}".`); throw new Error(`Expected piece length to be "65536", "262144", 524288" or "4194304" but it was "${file.info['piece length']}".`);
} }
if (typeof file.info.pieces !== 'string') { if (typeof file.info.pieces !== 'string') {
throw new Error(`Expected pieces to be a string but it was "${file.info.pieces}".`); throw new Error(`Expected pieces to be a string but it was "${file.info.pieces}".`);