Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flakey5/r2-localize

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flakey5/r2-localize

Allows for serving files from different R2 buckets based on the request's region.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

r2-localize

Allows for serving files from different R2 buckets based on the request's region.

Primary use cases would be lowering latency or serving localized files.

Usage

Initializing

const localizedBucket = localizeBucket({
  buckets: {
    wnam: env.WNAM_BUCKET,
    enam: env.ENAM_BUCKET,
    weur: env.WEUR_BUCKET,
    eeur: env.EEUR_BUCKET,
    apac: env.APAC_BUCKET,
  },
  // Region to use if one of the regions is undefined or we couldn't identify what region a colo is in/closest to
  fallbackRegion: 'wnam',
});

Head

// Heading a file
const object: R2Object | null = await localizedBucket.head('some-object', {
  request,
});

Get

const object: R2Object | R2ObjectBody | null = await localizedBucket.get(
  'some-object',
  {
    request,
    // R2GetOptions properties here, e.g.
    onlyIf: {
      // ...
    },
  }
);

Put

Note: this puts the object in the nearest bucket only. The other buckets are unaffected.

const object: R2Object | null = await localizedBucket.put(
  'some-object',
  'some-value',
  {
    request,
    // R2PutOptions properties here, e.g.
    onlyIf: {
      // ...
    },
  }
);

CreateMultipartUpload

Note: this puts the object in the nearest bucket only. The other buckets are unaffected.

const object: R2MultipartUpload = await localizedBucket.createMultipartUpload(
  'some-object',
  {
    request,
    // R2MultipartOptions properties here, e.g.
    httpMetadata: {
      // ...
    },
  }
);

ResumeMultipartUpload

Note: this puts the object in the nearest bucket only. The other buckets are unaffected.

const object: R2MultipartUpload = await localizedBucket.resumeMultipartUpload(
  'some-object',
  'upload id',
  { request }
);

Delete

Note: this deletes the object in the nearest bucket only. The other buckets are unaffected.

await localizedBucket.resumeMultipartUpload('some-object', 'upload id', {
  request,
});

List

const object: R2Objects = await localizedBucket.list({
  request,
  // R2ListOptions properties here, e.g.
  prefix: 'asd',
});

Accessing a specific region

To access the bucket of a specific region, you can pass in the region's name instead of the request object.

const object: R2Object | R2ObjectBody | null = await localizedBucket.get(
  'some-object',
  {
    region: 'wnam',
    // R2GetOptions properties here, e.g.
    onlyIf: {
      // ...
    },
  }
);

License

This repository is licensed under the terms of the MIT License.

FAQs

Package last updated on 06 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc