Skip to content

Commit

Permalink
Rename to s3Get (#7)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename s3Get
  • Loading branch information
AbdBarho authored Aug 9, 2022
1 parent e3b8799 commit adb742d
Show file tree
Hide file tree
Showing 13 changed files with 600 additions and 714 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Minimal express example:
```js
import express from 'express';
import { S3Client } from '@aws-sdk/client-s3';
import { getS3 } from 's3-serve';
import { s3Get } from 's3-serve';

const client = new S3Client(...);
const app = express();

app.get('/:file', async (req, res) => {
const { headers, body } = await getS3(client, {
const { headers, body } = await s3Get(client, {
Bucket: 'my-bucket',
Key: req.params.file
});
Expand All @@ -55,18 +55,18 @@ This library aims to be flexible by giving the developer full control over the i

VSCode intellisense by itself may answer all your questions!

### **getS3**
### **s3Get**

_getS3(client: [S3 Client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/s3client.html), options: [GetObjectCommandInput](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/getobjectcommandinput.html)): Promise\<[S3Response](./src/lib/S3Response.ts)>_
_s3Get(client: [S3 Client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/s3client.html), options: [GetObjectCommandInput](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/getobjectcommandinput.html)): Promise\<[S3Response](./src/lib/S3Response.ts)>_

Executes a [GetObjectCommand](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/getobjectcommand.html) using the given client. Returns an [S3Response](./src/lib/S3Response.ts) which contains all information needed to serve the file.

Note: `getS3` does neither cache nor store anything in memory, the requested file in `S3Response.body` is a `Readable` stream that can be piped as a response.
Note: `s3Get` does neither cache nor store anything in memory, the requested file in `S3Response.body` is a `Readable` stream that can be piped as a response.

### **extractGetArgs**
_extractGetArgs(headers: object): object_

Extracts and converts relevant headers from a request, so they can be fed into `getS3`'s `GetObjectCommandInput`.
Extracts and converts relevant headers from a request, so they can be fed into `s3Get`'s `GetObjectCommandInput`.



Expand All @@ -76,10 +76,10 @@ Extracts and converts relevant headers from a request, so they can be fed into `
Implement `express.static` but from s3 and with custom cache headers:

```js
import { getS3, extractGetArgs } from 's3-serve';
import { s3Get, extractGetArgs } from 's3-serve';

app.get('/:key(*)', async (req, res) => {
const response = await getS3(client, {
const response = await s3Get(client, {
Bucket,
Key: req.params.key || 'index.html',
...extractGetArgs(req.headers),
Expand Down
4 changes: 2 additions & 2 deletions examples/express.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { S3Client } from '@aws-sdk/client-s3';
import Express from 'express';
import dotenv from 'dotenv';
import { getS3, extractGetArgs } from '../build/index.js';
import { s3Get, extractGetArgs } from '../build/index.js';

dotenv.config();

Expand All @@ -20,7 +20,7 @@ app.get('/:key(*)', async (req, res) => {
if (Key === '') {
Key = 'index.html';
}
const response = await getS3(client, {
const response = await s3Get(client, {
Bucket,
Key,
...extractGetArgs(req.headers),
Expand Down
4 changes: 2 additions & 2 deletions examples/fastify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Fastify from 'fastify';
import { S3Client } from '@aws-sdk/client-s3';
import dotenv from 'dotenv';

import { getS3, extractGetArgs } from '../build/index.js';
import { s3Get, extractGetArgs } from '../build/index.js';

dotenv.config();

Expand All @@ -22,7 +22,7 @@ fastify.get('/*', async (req, res) => {
if (Key === '') {
Key = 'index.html';
}
const { body, statusCode, headers } = await getS3(client, {
const { body, statusCode, headers } = await s3Get(client, {
Bucket,
Key,
...extractGetArgs(req.headers),
Expand Down
130 changes: 55 additions & 75 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"@types/express": "^4.17.13",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"fastify": "^4.3.0"
"fastify": "^4.4.0"
}
}
Loading

0 comments on commit adb742d

Please sign in to comment.