INNER CODE UNIT · JavaScript

parseSha256Sidecar

agent-sh/agentsys · lib/binary/index.js:229

function parseSha256Sidecar(body) {
  if (typeof body !== 'string') body = String(body || '');
  const match = body.trim().match(/^([A-Fa-f0-9]{64})\b/);
  if (!match) {
    throw new Error('Could not parse SHA-256 digest from sidecar body');
  }
  return match[1].toLowerCase();
}

/**
 * Fetch and parse a `.sha256` sidecar next to an asset URL.
 * @param {string} assetUrl full URL of the archive (not the sidecar)
 * @returns {Promise<string>} lower-cased hex digest
 */
async function downloadSha256(assetUrl) {
  const sidecarUrl = assetUrl + '.sha256';
  const buf = await downloadToBuffer(sidecarUrl);
  return parseSha256Sidecar(buf.toString('utf8'));

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…