diff --git a/src/deb/deb-builder.mts b/src/deb/deb-builder.mts index 35d8cee..e07a6f9 100644 --- a/src/deb/deb-builder.mts +++ b/src/deb/deb-builder.mts @@ -112,7 +112,7 @@ export class DebBuilder implements Deployer { releaseContent += 'SHA256:\n'; for (const { address, size, name } of indices) { - releaseContent += ` ${Buffer.from(address.sha256).toString('hex')}\t${size}\t${name}`; + releaseContent += ` ${Buffer.from(address.sha256).toString('hex')}\t${size}\t${name}\n`; } const tempReleaseFile = path.join(this.tempPath, `Release-${randomBytes(4).toString('hex')}`); @@ -231,12 +231,13 @@ export class DebBuilder implements Deployer { unlinkSync(metaFile); } - const packagesContentDescription = await storeStreamInCas(path.resolve(binaryPath, 'by-hash'), Readable.from(packagesContent)); - binaryPackageIndices.push({ - name: `${component}/${binarySubdir}/Packages.gz`, - size: packagesContentDescription.size, - address: packagesContentDescription.address, - }); + const storePackageIndex = async(shortName: string, store: (root: string, stream: NodeJS.ReadableStream) => Promise) => { + const name = `${component}/${binarySubdir}/${shortName}`; + const { size, address } = await store(path.resolve(binaryPath, 'by-hash'), Readable.from(packagesContent)); + binaryPackageIndices.push({ name, size, address }); + }; + await storePackageIndex('Packages', storeStreamInCas); + await storePackageIndex('Packages.gz', storeGzippedStreamInCas); }), )); }); @@ -264,13 +265,16 @@ interface ContentDescription { address: ContentAddress; } +async function storeGzippedStreamInCas(root: string, stream: NodeJS.ReadableStream): Promise { + const gzip = createGzip({ level: 9 }); + const gzippedStream = new PassThrough(); + await pipeline(stream, gzip, gzippedStream); + return storeStreamInCas(root, gzippedStream); +} + // https://wiki.debian.org/DebianRepository/Format#indices_acquisition_via_hashsums_.28by-hash.29 async function storeStreamInCas(root: string, stream: NodeJS.ReadableStream): Promise { - // compress and store in a buffer - const gzip = createGzip({ level: 9 }); - const gzippedContent = new PassThrough(); - await pipeline(stream, gzip, gzippedContent); - const contentBuffer = await buffer(gzippedContent); + const contentBuffer = await buffer(stream); // compute a digest const sha256Hash = createHash('sha256');