Skip to content

Commit

Permalink
pass Blob as body
Browse files Browse the repository at this point in the history
  • Loading branch information
LiviaMedeiros committed Sep 19, 2023
1 parent 6670b36 commit f877129
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/methods.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const GET = async (url, { headers, integrity, signal }) => {
async body => [
body,
await statsAsOptions(
Object.assign(stats, { size: BigInt(body.byteLength) }),
Object.assign(stats, { size: BigInt(body.size) }),
{ status: 206 }
),
]
Expand Down
5 changes: 2 additions & 3 deletions lib/sri.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const algoFromSRI = new Map([
]);

const validatedBody = async (integrity, body) => {
// TODO: use blob directly, when it wouldn't break in Response
body = await new Blob(body).arrayBuffer();
body = new Blob(body);

if (!integrity)
return body;
Expand All @@ -16,7 +15,7 @@ const validatedBody = async (integrity, body) => {
const [algo, sign] = integrity.trim().split('-');
const hash = Buffer.from(await crypto.subtle.digest(
algoFromSRI.get(algo.toLowerCase()) ?? algo,
body
await body.arrayBuffer()
)).toString('base64');
if (sign !== hash)
throw new TypeError('Integrity mismatch');
Expand Down

0 comments on commit f877129

Please sign in to comment.