Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected change in R2Checksums types #2211

Closed
Cherry opened this issue Jun 4, 2024 · 2 comments · Fixed by #2212
Closed

Unexpected change in R2Checksums types #2211

Cherry opened this issue Jun 4, 2024 · 2 comments · Fixed by #2212
Assignees
Labels
types Related to @cloudflare/workers-types

Comments

@Cherry
Copy link
Contributor

Cherry commented Jun 4, 2024

Previously ([email protected]), R2 checksums were defined like this:

declare interface R2Checksums {
  readonly md5?: ArrayBuffer;
  readonly sha1?: ArrayBuffer;
  readonly sha256?: ArrayBuffer;
  readonly sha384?: ArrayBuffer;
  readonly sha512?: ArrayBuffer;
  toJSON(): R2StringChecksums;
}

which meant code like this (pseudo) was perfectly valid:

const file = await env.MY_BUCKET.get('file.txt');
let checksum: ArrayBuffer | null = null;
if(file?.checksums?.md5){
	checksum = file.checksums.md5.slice(0, 8); // not really how this would work, but illustrates the change
}

Now ([email protected]), it's defined like this:

declare interface R2Checksums {
  readonly md5?: ArrayBufferView;
  readonly sha1?: ArrayBufferView;
  readonly sha256?: ArrayBufferView;
  readonly sha384?: ArrayBufferView;
  readonly sha512?: ArrayBufferView;
  toJSON(): R2StringChecksums;
}

which implies you have to do .buffer on each of the checksums to access it, like:

checksum = file.checksums.md5.buffer.slice(0, 8);

but this then throws a TypeError: TypeError: Cannot read properties of undefined (reading 'slice')

I suspect this was caused by #2201. cc @jasnell

@Cherry Cherry added the types Related to @cloudflare/workers-types label Jun 4, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jun 4, 2024
@jasnell
Copy link
Member

jasnell commented Jun 4, 2024

That's odd. Will add a type override. Those should still be ArrayBuffer

@jasnell
Copy link
Member

jasnell commented Jun 4, 2024

Ok, fixed merged in master. Should appear in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Related to @cloudflare/workers-types
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants