Skip to content

Commit 77c60c6

Browse files
chore: wip
1 parent 8131f00 commit 77c60c6

File tree

7 files changed

+86
-23
lines changed

7 files changed

+86
-23
lines changed

storage/framework/core/storage/src/drivers/aws.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ChecksumOptions, DirectoryListing, FileContents, MimeTypeOptions, PublicUrlOptions, StatEntry, TemporaryUrlOptions } from '@flystorage/file-storage'
22
import type { StorageDriver } from '@stacksjs/types'
3+
import type { Buffer } from 'node:buffer'
34
import { S3Client } from '@aws-sdk/client-s3'
45
import { AwsS3StorageAdapter } from '@flystorage/aws-s3'
56
import { FileStorage } from '@flystorage/file-storage'
@@ -12,77 +13,92 @@ const adapter = new AwsS3StorageAdapter(client, {
1213

1314
export const awsStorage: FileStorage = new FileStorage(adapter)
1415

15-
export const local: StorageDriver = {
16+
export const aws: StorageDriver = {
1617
async write(path: string, contents: FileContents): Promise<void> {
17-
await localStorage.write(path, contents)
18+
await awsStorage.write(path, contents)
1819
},
1920

2021
async deleteFile(path: string): Promise<void> {
21-
await localStorage.deleteFile(path)
22+
await awsStorage.deleteFile(path)
2223
},
2324

2425
async createDirectory(path: string): Promise<void> {
25-
await localStorage.createDirectory(path)
26+
await awsStorage.createDirectory(path)
2627
},
2728

2829
async moveFile(from: string, to: string): Promise<void> {
29-
await localStorage.moveFile(from, to)
30+
await awsStorage.moveFile(from, to)
3031
},
3132

3233
async copyFile(from: string, to: string): Promise<void> {
33-
await localStorage.copyFile(from, to)
34+
await awsStorage.copyFile(from, to)
3435
},
3536

3637
async stat(path: string): Promise<StatEntry> {
37-
return await localStorage.stat(path)
38+
return await awsStorage.stat(path)
3839
},
3940

4041
list(path: string, options: { deep: boolean }): DirectoryListing {
41-
return localStorage.list(path, options)
42+
return awsStorage.list(path, options)
4243
},
4344

4445
async changeVisibility(path: string, visibility: string): Promise<void> {
45-
await localStorage.changeVisibility(path, visibility)
46+
await awsStorage.changeVisibility(path, visibility)
4647
},
4748

4849
async visibility(path: string): Promise<string> {
49-
return await localStorage.visibility(path)
50+
return await awsStorage.visibility(path)
5051
},
5152

5253
async fileExists(path: string): Promise<boolean> {
53-
return await localStorage.fileExists(path)
54+
return await awsStorage.fileExists(path)
5455
},
5556

5657
async directoryExists(path: string): Promise<boolean> {
57-
return await localStorage.directoryExists(path)
58+
return await awsStorage.directoryExists(path)
5859
},
5960

6061
async publicUrl(path: string, options: PublicUrlOptions): Promise<string> {
61-
return await localStorage.publicUrl(path, options)
62+
return await awsStorage.publicUrl(path, options)
6263
},
6364

6465
async temporaryUrl(path: string, options: TemporaryUrlOptions): Promise<string> {
65-
return await localStorage.temporaryUrl(path, options)
66+
return await awsStorage.temporaryUrl(path, options)
6667
},
6768

6869
async checksum(path: string, options: ChecksumOptions): Promise<string> {
69-
return await localStorage.checksum(path, options)
70+
return await awsStorage.checksum(path, options)
7071
},
7172

7273
async mimeType(path: string, options: MimeTypeOptions): Promise<string> {
73-
return await localStorage.mimeType(path, options)
74+
return await awsStorage.mimeType(path, options)
7475
},
7576

7677
async lastModified(path: string): Promise<number> {
77-
return await localStorage.lastModified(path)
78+
return await awsStorage.lastModified(path)
7879
},
7980

8081
async fileSize(path: string): Promise<number> {
81-
return await localStorage.fileSize(path)
82+
return await awsStorage.fileSize(path)
8283
},
8384

8485
async read(path: string): Promise<FileContents> {
85-
const contents = await localStorage.read(path)
86+
const contents = await awsStorage.read(path)
87+
88+
return contents
89+
},
90+
async readToString(path: string): Promise<string> {
91+
const contents = await localStorage.readToString(path)
92+
93+
return contents
94+
},
95+
async readToBuffer(path: string): Promise<Buffer> {
96+
const contents = await localStorage.readToBuffer(path)
97+
98+
return contents
99+
},
100+
async readToUint8Array(path: string): Promise<Uint8Array> {
101+
const contents = await localStorage.readToUint8Array(path)
86102

87103
return contents
88104
},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * as aws from './aws'
2-
export * as local from './local'
3-
export * as memory from './memory'
1+
export * from './aws'
2+
export * from './local'
3+
export * from './memory'

storage/framework/core/storage/src/drivers/local.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { ChecksumOptions, DirectoryListing, FileContents, MimeTypeOptions, PublicUrlOptions, StatEntry, TemporaryUrlOptions } from '@flystorage/file-storage'
22
import type { StorageDriver } from '@stacksjs/types'
33

4+
import type { Buffer } from 'node:buffer'
45
import { resolve } from 'node:path'
56

67
import process from 'node:process'
78
import { FileStorage } from '@flystorage/file-storage'
89
import { LocalStorageAdapter } from '@flystorage/local-fs'
910

10-
const rootDirectory = resolve(process.cwd(), 'my-files')
11+
const rootDirectory = resolve(process.cwd())
1112
const adapter = new LocalStorageAdapter(rootDirectory)
1213

1314
export const localStorage: FileStorage = new FileStorage(adapter)
@@ -86,4 +87,20 @@ export const local: StorageDriver = {
8687

8788
return contents
8889
},
90+
91+
async readToString(path: string): Promise<string> {
92+
const contents = await localStorage.readToString(path)
93+
94+
return contents
95+
},
96+
async readToBuffer(path: string): Promise<Buffer> {
97+
const contents = await localStorage.readToBuffer(path)
98+
99+
return contents
100+
},
101+
async readToUint8Array(path: string): Promise<Uint8Array> {
102+
const contents = await localStorage.readToUint8Array(path)
103+
104+
return contents
105+
},
89106
}

storage/framework/core/storage/src/drivers/memory.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { ChecksumOptions, DirectoryListing, FileContents, MimeTypeOptions,
22

33
import type { StorageDriver } from '@stacksjs/types'
44

5+
import type { Buffer } from 'node:buffer'
6+
57
import { FileStorage } from '@flystorage/file-storage'
68
import { InMemoryStorageAdapter } from '@flystorage/in-memory'
79

@@ -81,6 +83,21 @@ export const memory: StorageDriver = {
8183
async read(path: string): Promise<FileContents> {
8284
const contents = await localStorage.read(path)
8385

86+
return contents
87+
},
88+
async readToString(path: string): Promise<string> {
89+
const contents = await localStorage.readToString(path)
90+
91+
return contents
92+
},
93+
async readToBuffer(path: string): Promise<Buffer> {
94+
const contents = await localStorage.readToBuffer(path)
95+
96+
return contents
97+
},
98+
async readToUint8Array(path: string): Promise<Uint8Array> {
99+
const contents = await localStorage.readToUint8Array(path)
100+
84101
return contents
85102
},
86103
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
import { describe, expect, it, jest } from 'bun:test'
22
import { local } from '../src/drivers'
3+
4+
describe('@stacksjs/storage', () => {
5+
it('should read the file', async () => {
6+
const contents = await local.readToString('./dirs/sample.txt')
7+
8+
console.log(contents)
9+
})
10+
})

storage/framework/core/types/src/storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ChecksumOptions, DirectoryListing, FileContents, MimeTypeOptions, PublicUrlOptions, StatEntry, TemporaryUrlOptions } from '@flystorage/file-storage'
2+
import type { Buffer } from 'node:buffer'
23

34
export interface StorageOptions {
45
/**
@@ -27,6 +28,9 @@ export interface StorageDriver {
2728
lastModified: (path: string) => Promise<number>
2829
fileSize: (path: string) => Promise<number>
2930
read: (path: string) => Promise<FileContents>
31+
readToString: (path: string) => Promise<string>
32+
readToBuffer: (path: string) => Promise<Buffer>
33+
readToUint8Array: (path: string) => Promise<Uint8Array>
3034
deleteFile: (path: string) => Promise<void>
3135
copyFile: (from: string, to: string) => Promise<void>
3236
moveFile: (from: string, to: string) => Promise<void>

0 commit comments

Comments
 (0)