Skip to content

Commit

Permalink
Rename method set to put
Browse files Browse the repository at this point in the history
  • Loading branch information
jasny committed Jul 4, 2023
1 parent 450b8db commit a7f0c96
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface Bucket {
* @param key The path to the file.
* @param content The contents of the file.
*/
set(key: string, content: Uint8Array | string): Promise<void>;
put(key: string, content: Uint8Array | string): Promise<void>;

/**
* Delete a file.
Expand Down Expand Up @@ -83,7 +83,7 @@ console.log(hasFile);
const fileContent = await localBucket.get('file.txt');
console.log(fileContent);

await localBucket.set('file.txt', 'Hello, World!');
await localBucket.put('file.txt', 'Hello, World!');

await localBucket.delete('file.txt');
```
Expand Down Expand Up @@ -114,7 +114,7 @@ console.log(hasFile);
const fileContent = await s3Bucket.get('file.txt');
console.log(fileContent);

await s3Bucket.set('file.txt', 'Hello, S3!');
await s3Bucket.put('file.txt', 'Hello, S3!');

await s3Bucket.delete('file.txt');
```
Expand Down Expand Up @@ -154,7 +154,7 @@ console.log(hasFile);
const fileContent = await azureBucket.get('file.txt');
console.log(fileContent);

await azureBucket.set('file.txt', 'Hello, Azure!');
await azureBucket.put('file.txt', 'Hello, Azure!');

await azureBucket.delete('file.txt');
```
Expand Down Expand Up @@ -192,7 +192,7 @@ console.log(hasFile);
const fileContent = await gcsBucket.get('file.txt');
console.log(fileContent);

await gcsBucket.set('file.txt', 'Hello, GCS!');
await gcsBucket.put('file.txt', 'Hello, GCS!');

await gcsBucket.delete('file.txt');
```
Expand Down
2 changes: 1 addition & 1 deletion src/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class AzureBucket implements Bucket {
return encoding ? await body.text() : Buffer.from(await body.arrayBuffer());
}

async set(key: string, content: string | Uint8Array): Promise<void> {
async put(key: string, content: string | Uint8Array): Promise<void> {
const blobClient = this.container.getBlockBlobClient(this.path(key));

if (typeof content === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/gcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class GCSBucket implements Bucket {
return encoding ? data.toString(encoding) : data;
}

async set(key: string, content: string | Uint8Array): Promise<void> {
async put(key: string, content: string | Uint8Array): Promise<void> {
const file = this.bucket.file(this.path(key));
await file.save(typeof content === 'string' ? content : Buffer.from(content));
}
Expand Down
2 changes: 1 addition & 1 deletion src/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class LocalBucket implements Bucket {
return fs.readFile(this.path(key), encoding);
}

async set(key: string, content: string | Uint8Array): Promise<void> {
async put(key: string, content: string | Uint8Array): Promise<void> {
if (key === '') throw new Error('key is empty');
const path = this.path(key);

Expand Down
2 changes: 1 addition & 1 deletion src/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class S3Bucket implements Bucket {
return encoding ? await content.transformToString(encoding) : Buffer.from(await content.transformToByteArray());
}

async set(key: string, content: string | Uint8Array): Promise<void> {
async put(key: string, content: string | Uint8Array): Promise<void> {
const params = {
Bucket: this.bucketName,
Key: this.path(key),
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Bucket {
get(key: string, encoding?: null): Promise<Buffer>;
get(key: string, encoding: BufferEncoding): Promise<string>;

set(key: string, content: string | Uint8Array): Promise<void>;
put(key: string, content: string | Uint8Array): Promise<void>;

delete(key: string): Promise<void>;
}
6 changes: 3 additions & 3 deletions test/azure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('AzureBucket', () => {
it('should put an object with the specified key and binary value', async () => {
blockBlobClient.uploadData.resolves();

await bucket.set('file1.txt', Uint8Array.from([1, 2, 3]));
await bucket.put('file1.txt', Uint8Array.from([1, 2, 3]));

expect(container.getBlockBlobClient.calledOnce).to.be.true;
expect(container.getBlockBlobClient.firstCall.args[0]).to.equal('file1.txt');
Expand All @@ -190,7 +190,7 @@ describe('AzureBucket', () => {
it('should put an object with the specified key and string value', async () => {
blockBlobClient.upload.resolves();

await bucket.set('file1.txt', 'content 1');
await bucket.put('file1.txt', 'content 1');

expect(container.getBlockBlobClient.calledOnce).to.be.true;
expect(container.getBlockBlobClient.firstCall.args[0]).to.equal('file1.txt');
Expand All @@ -202,7 +202,7 @@ describe('AzureBucket', () => {

describe('with prefix', () => {
it('should put an object with the specified key and value', async () => {
await bucketSub.set('file1.txt', 'content 1');
await bucketSub.put('file1.txt', 'content 1');

expect(container.getBlockBlobClient.calledOnce).to.be.true;
expect(container.getBlockBlobClient.firstCall.args[0]).to.equal('sub/file1.txt');
Expand Down
6 changes: 3 additions & 3 deletions test/gcs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('GCSBucket', () => {
});

it('should put an object with a string value', async () => {
await bucket.set('file1.txt', 'content 1');
await bucket.put('file1.txt', 'content 1');

expect(gcsBucket.file.calledOnce).to.be.true;
expect(gcsBucket.file.firstCall.args[0]).to.equal('file1.txt');
Expand All @@ -172,7 +172,7 @@ describe('GCSBucket', () => {
});

it('should put an object with a binary value', async () => {
await bucket.set('file1.txt', Uint8Array.from([1, 2, 3, 4]));
await bucket.put('file1.txt', Uint8Array.from([1, 2, 3, 4]));

expect(gcsBucket.file.calledOnce).to.be.true;
expect(gcsBucket.file.firstCall.args[0]).to.equal('file1.txt');
Expand All @@ -183,7 +183,7 @@ describe('GCSBucket', () => {

describe('with prefix', () => {
it('should put an object with a string value', async () => {
await bucketSub.set('file1.txt', 'content 1');
await bucketSub.put('file1.txt', 'content 1');

expect(gcsBucket.file.calledOnce).to.be.true;
expect(gcsBucket.file.firstCall.args[0]).to.equal('sub/file1.txt');
Expand Down
6 changes: 3 additions & 3 deletions test/local.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('LocalBucket', () => {
const key = 'new-file.txt';
const value = 'new file content';

await bucket.set(key, value);
await bucket.put(key, value);
const content = await fs.readFile(`/base/path/${key}`, 'utf-8');

expect(content).to.equal(value);
Expand All @@ -89,7 +89,7 @@ describe('LocalBucket', () => {
const key = 'nested/folder/file.txt';
const value = 'nested file content';

await bucket.set(key, value);
await bucket.put(key, value);
const content = await fs.readFile(`/base/path/${key}`, 'utf-8');

expect(content).to.equal(value);
Expand All @@ -99,7 +99,7 @@ describe('LocalBucket', () => {
const bucket = new LocalBucket('/base/path');

try {
await bucket.set('', 'value');
await bucket.put('', 'value');
expect.fail('Expected an error to be thrown');
} catch (error) {
expect(error.message).to.equal('key is empty');
Expand Down
4 changes: 2 additions & 2 deletions test/s3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('S3Bucket', () => {
});

it('should put an object with the specified key and value', async () => {
await bucket.set('file1.txt', 'content 1');
await bucket.put('file1.txt', 'content 1');

expect(s3Client.putObject.calledOnce).to.be.true;
expect(s3Client.putObject.firstCall.args[0]).to.deep.equal({
Expand All @@ -203,7 +203,7 @@ describe('S3Bucket', () => {

describe('with prefix', () => {
it('should put an object with the specified key and value', async () => {
await bucketSub.set('file1.txt', 'content 1');
await bucketSub.put('file1.txt', 'content 1');

expect(s3Client.putObject.calledOnce).to.be.true;
expect(s3Client.putObject.firstCall.args[0]).to.deep.equal({
Expand Down

0 comments on commit a7f0c96

Please sign in to comment.