Creates an S3 endpoint that maps to a local directory for testing and local development.
Go to file
2024-05-29 14:16:00 +02:00
.vscode fix(core): update 2021-12-18 01:41:50 +01:00
test fix(structure): format 2022-04-14 10:38:14 +02:00
ts fix(core): remove tslint 2022-07-30 15:50:38 +02:00
.gitignore fix(core): update 2021-12-18 01:41:50 +01:00
.gitlab-ci.yml fix(structure): format 2022-04-14 10:38:14 +02:00
license fix(core): update 2021-12-18 01:41:50 +01:00
npmextra.json update tsconfig 2024-04-14 18:16:08 +02:00
package-lock.json 2.1.1 2022-07-30 15:50:38 +02:00
package.json update description 2024-05-29 14:16:00 +02:00
pnpm-lock.yaml switch to new org scheme 2023-07-11 01:32:01 +02:00
readme.hints.md update tsconfig 2024-04-14 18:16:08 +02:00
readme.md update tsconfig 2024-04-14 18:16:08 +02:00
tsconfig.json update tsconfig 2024-04-01 21:40:47 +02:00

@push.rocks/smarts3

create an s3 endpoint that maps to a local directory

Install

To use @push.rocks/smarts3 in your project, you'll need to install it via npm. You can do so by running the following command in your project's root directory:

npm install @push.rocks/smarts3 --save

This will add @push.rocks/smarts3 as a dependency to your project's package.json file and download the package into the node_modules directory.

Usage

@push.rocks/smarts3 is designed to make it easy for developers to create an S3 compatible endpoint that maps to a local directory. This can be particularly useful for local development and testing, allowing you to mimic S3's functionality without the need for an actual S3 bucket.

Below, we'll go through how to get started, set up an S3 server, manage buckets, and perform common operations.

Setting up the S3 Server

First, let's see how to set up and start an S3 server instance.

import { Smarts3 } from '@push.rocks/smarts3';

async function startServer() {
  // Creating and starting the Smarts3 instance
  const smarts3Instance = await Smarts3.createAndStart({
    port: 3000, // optional, defaults to 3000
    cleanSlate: true // optional, if set to true, it will empty the directory on start
  });

  console.log('S3 server is up and running...');
  return smarts3Instance;
}

startServer().catch(console.error);

Creating a Bucket

With the server up and running, you can now create buckets.

async function createBucket(smarts3Instance: Smarts3) {
  // Creating a new bucket
  const bucket = await smarts3Instance.createBucket('my-awesome-bucket');
  console.log(`Bucket created: ${bucket.name}`);
}

// Assuming startServer() has been called and smarts3Instance has been received
createBucket(smarts3Instance).catch(console.error);

Accessing Buckets and Uploading Files

To perform actions like uploading files, you will need to work with the underlying SmartBucket module. The SmartBucket module is part of the @push.rocks ecosystem and integrated into smarts3 for easy bucket and file management.

import { SmartBucket, Bucket } from '@pushrocks/smartbucket';

async function uploadFile(smarts3Instance: Smarts3) {
  // Getting the S3 descriptor to configure SmartBucket
  const s3Descriptor = await smarts3Instance.getS3Descriptor();
  
  const smartbucketInstance = new SmartBucket(s3Descriptor);
  const bucket: Bucket = await smartbucketInstance.getBucket('my-awesome-bucket');

  // Now let's upload a file to the bucket
  const baseDirectory = await bucket.getBaseDirectory();
  await baseDirectory.fastStore('hello.txt', 'Hello, world!');

  console.log('File uploaded successfully.');
}

uploadFile(smarts3Instance).catch(console.error);

Stopping the Server

Finally, when you are done, you can stop the Smarts3 server as follows:

async function stopServer(smarts3Instance: Smarts3) {
  await smarts3Instance.stop();
  console.log('S3 server has been stopped.');
}

stopServer(smarts3Instance).catch(console.error);

Complete Integration

Integrating @push.rocks/smarts3 into your development workflow offers a seamless way to mimic Amazon S3 locally. By creating an S3-compatible endpoint that maps to a local directory, you can develop and test applications that interact with S3 without incurring any cost or requiring internet connectivity. Thanks to its API, @push.rocks/smarts3 makes it easy to programmatically manage your local S3 server, create and delete buckets, and upload or download files, ensuring that your applications can be designed with cloud scalability in mind, right from the start.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.