1
1
import type { ChecksumOptions , DirectoryListing , FileContents , MimeTypeOptions , PublicUrlOptions , StatEntry , TemporaryUrlOptions } from '@flystorage/file-storage'
2
2
import type { StorageDriver } from '@stacksjs/types'
3
+ import type { Buffer } from 'node:buffer'
3
4
import { S3Client } from '@aws-sdk/client-s3'
4
5
import { AwsS3StorageAdapter } from '@flystorage/aws-s3'
5
6
import { FileStorage } from '@flystorage/file-storage'
@@ -12,77 +13,92 @@ const adapter = new AwsS3StorageAdapter(client, {
12
13
13
14
export const awsStorage : FileStorage = new FileStorage ( adapter )
14
15
15
- export const local : StorageDriver = {
16
+ export const aws : StorageDriver = {
16
17
async write ( path : string , contents : FileContents ) : Promise < void > {
17
- await localStorage . write ( path , contents )
18
+ await awsStorage . write ( path , contents )
18
19
} ,
19
20
20
21
async deleteFile ( path : string ) : Promise < void > {
21
- await localStorage . deleteFile ( path )
22
+ await awsStorage . deleteFile ( path )
22
23
} ,
23
24
24
25
async createDirectory ( path : string ) : Promise < void > {
25
- await localStorage . createDirectory ( path )
26
+ await awsStorage . createDirectory ( path )
26
27
} ,
27
28
28
29
async moveFile ( from : string , to : string ) : Promise < void > {
29
- await localStorage . moveFile ( from , to )
30
+ await awsStorage . moveFile ( from , to )
30
31
} ,
31
32
32
33
async copyFile ( from : string , to : string ) : Promise < void > {
33
- await localStorage . copyFile ( from , to )
34
+ await awsStorage . copyFile ( from , to )
34
35
} ,
35
36
36
37
async stat ( path : string ) : Promise < StatEntry > {
37
- return await localStorage . stat ( path )
38
+ return await awsStorage . stat ( path )
38
39
} ,
39
40
40
41
list ( path : string , options : { deep : boolean } ) : DirectoryListing {
41
- return localStorage . list ( path , options )
42
+ return awsStorage . list ( path , options )
42
43
} ,
43
44
44
45
async changeVisibility ( path : string , visibility : string ) : Promise < void > {
45
- await localStorage . changeVisibility ( path , visibility )
46
+ await awsStorage . changeVisibility ( path , visibility )
46
47
} ,
47
48
48
49
async visibility ( path : string ) : Promise < string > {
49
- return await localStorage . visibility ( path )
50
+ return await awsStorage . visibility ( path )
50
51
} ,
51
52
52
53
async fileExists ( path : string ) : Promise < boolean > {
53
- return await localStorage . fileExists ( path )
54
+ return await awsStorage . fileExists ( path )
54
55
} ,
55
56
56
57
async directoryExists ( path : string ) : Promise < boolean > {
57
- return await localStorage . directoryExists ( path )
58
+ return await awsStorage . directoryExists ( path )
58
59
} ,
59
60
60
61
async publicUrl ( path : string , options : PublicUrlOptions ) : Promise < string > {
61
- return await localStorage . publicUrl ( path , options )
62
+ return await awsStorage . publicUrl ( path , options )
62
63
} ,
63
64
64
65
async temporaryUrl ( path : string , options : TemporaryUrlOptions ) : Promise < string > {
65
- return await localStorage . temporaryUrl ( path , options )
66
+ return await awsStorage . temporaryUrl ( path , options )
66
67
} ,
67
68
68
69
async checksum ( path : string , options : ChecksumOptions ) : Promise < string > {
69
- return await localStorage . checksum ( path , options )
70
+ return await awsStorage . checksum ( path , options )
70
71
} ,
71
72
72
73
async mimeType ( path : string , options : MimeTypeOptions ) : Promise < string > {
73
- return await localStorage . mimeType ( path , options )
74
+ return await awsStorage . mimeType ( path , options )
74
75
} ,
75
76
76
77
async lastModified ( path : string ) : Promise < number > {
77
- return await localStorage . lastModified ( path )
78
+ return await awsStorage . lastModified ( path )
78
79
} ,
79
80
80
81
async fileSize ( path : string ) : Promise < number > {
81
- return await localStorage . fileSize ( path )
82
+ return await awsStorage . fileSize ( path )
82
83
} ,
83
84
84
85
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 )
86
102
87
103
return contents
88
104
} ,
0 commit comments