lopata 0.14.2 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lopata",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -264,7 +264,7 @@ export class R2MultipartUpload {
264
264
  this.limits = limits
265
265
  }
266
266
 
267
- async uploadPart(partNumber: number, data: ArrayBuffer | Uint8Array | string | ReadableStream): Promise<{ partNumber: number; etag: string }> {
267
+ async uploadPart(partNumber: number, data: ArrayBuffer | ArrayBufferView | string | ReadableStream): Promise<{ partNumber: number; etag: string }> {
268
268
  // Verify upload exists and is not aborted/completed
269
269
  const upload = this.db
270
270
  .query<MultipartRow, [string, string]>(
@@ -276,10 +276,10 @@ export class R2MultipartUpload {
276
276
  let buf: ArrayBuffer
277
277
  if (typeof data === 'string') {
278
278
  buf = new TextEncoder().encode(data).buffer as ArrayBuffer
279
- } else if (data instanceof Uint8Array) {
280
- buf = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength) as ArrayBuffer
281
279
  } else if (data instanceof ArrayBuffer) {
282
280
  buf = data
281
+ } else if (ArrayBuffer.isView(data)) {
282
+ buf = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength) as ArrayBuffer
283
283
  } else {
284
284
  // ReadableStream
285
285
  const chunks: Uint8Array[] = []
@@ -495,11 +495,14 @@ export class FileR2Bucket {
495
495
  }
496
496
 
497
497
  private async readValue(
498
- value: string | ArrayBuffer | ReadableStream | Blob | null,
498
+ value: string | ArrayBuffer | ArrayBufferView | ReadableStream | Blob | null,
499
499
  ): Promise<ArrayBuffer> {
500
500
  if (value === null) return new ArrayBuffer(0)
501
501
  if (typeof value === 'string') return new TextEncoder().encode(value).buffer as ArrayBuffer
502
502
  if (value instanceof ArrayBuffer) return value
503
+ if (ArrayBuffer.isView(value)) {
504
+ return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength) as ArrayBuffer
505
+ }
503
506
  if (value instanceof Blob) return await value.arrayBuffer()
504
507
  // ReadableStream
505
508
  const chunks: Uint8Array[] = []
@@ -521,7 +524,7 @@ export class FileR2Bucket {
521
524
 
522
525
  async put(
523
526
  key: string,
524
- value: string | ArrayBuffer | ReadableStream | Blob | null,
527
+ value: string | ArrayBuffer | ArrayBufferView | ReadableStream | Blob | null,
525
528
  options?: R2PutOptions,
526
529
  ): Promise<R2Object | null> {
527
530
  this.validateKey(key)