@@ -155,68 +155,39 @@ await storage.move('folder/DASdsakdjas912831jhdasnm.txt', 'folder/test/move.txt'
155
155
156
156
### Subscribing configs of disks in runtime
157
157
158
- > You can subscribe the disks configs in runtime using addConfig, removeConfig and resetConfig methods
158
+ > You can subscribe the disks configs in runtime using in Storage constructor or disk method
159
159
160
160
``` ts
161
+ // Using disk method approach
161
162
// File created on storage/newAppFolder/file.txt
162
163
storage
163
- .addConfig ( ' root ' , Path .noBuild ().storage (' newAppFolder' ))
164
+ .disk ( ' local ' , { root: Path .noBuild ().storage (' newAppFolder' ) } )
164
165
.put (' file.txt' , Buffer .from (' Hello World' ))
165
166
166
- // Will use the default: storage/app/file.txt
167
- storage
168
- .removeConfig (' root' )
169
- .put (' file.txt' , Buffer .from (' Hello World' ))
167
+ // Using constructor method approach
168
+ const newStorage = new Storage ({ root: Path .noBuild ().storage (' newAppFolder' ) })
170
169
171
- // resetConfig removes all the configs from the Storage instance
172
- // Will use the default: storage/app/file. txt
173
- storage
174
- . resetConfigs ()
175
- . put ( ' file.txt ' , Buffer . from ( ' Hello World ' ))
170
+ // File created on storage/newAppFolder/file2.txt
171
+ newStorage . put ( ' file2. txt' , Buffer . from ( ' Hello World ' ))
172
+
173
+ // You can reset configs using an empty object in the disk method
174
+ storage . disk ( ' local ' , {}) // Clear the runtime configuration
176
175
```
177
176
178
177
### Using S3 or GCS disk
179
178
180
179
> You can use ** s3** or ** gcs** disk to make all this actions inside buckets
181
180
182
181
``` ts
182
+ // Saves to S3
183
183
storage .disk (' s3' ).put (' folder/file.txt' , Buffer .from (' Hello world!' ))
184
- ```
185
-
186
- > It could be a little repetitive calling disk all the time, so you can change the default disk for that storage instance
187
-
188
- ``` ts
189
- storage .changeDefaultDisk (' gcs' )
190
-
191
- // All storage actions of this instance will use gcs from now on
192
- storage .put (' folder/file.txt' , Buffer .from (' Hello world!' ))
193
- ```
194
-
195
- > Be careful with ** addConfig** , ** removeConfig** and ** resetConfig** because they create a new instance
196
- > of the default driver you are using, if you want to subscribe some config and use a different disk,
197
- > use this methods first, example:
198
-
199
- ``` ts
200
- proccess .env .FILESYSTEM_DISK = ' local'
201
-
202
- // BAD!!!!!
203
- // This will create the file using local disk
204
- storage
205
- .disk (' s3' )
206
- .addConfig (' bucket' , ' test-bucket' )
207
- .put (' file.txt' , Buffer .from (' Hello World' ))
208
-
209
- // GOOD!!!!!
210
- // This will create the file using s3 disk
211
- storage
212
- .addConfig (' bucket' , ' test-bucket' )
213
- .disk (' s3' )
214
- .put (' file.txt' , Buffer .from (' Hello World' ))
184
+ // Saves to GCS
185
+ storage .disk (' gcs' ).put (' folder/file.txt' , Buffer .from (' Hello world!' ))
215
186
```
216
187
217
188
### Extending disks and drivers
218
189
219
- > Nowadays, @secjs/storage has only LocalDriver and S3Driver support, but you can extend the drivers for Storage class if you implement DriverContract interface
190
+ > Nowadays, @secjs/storage has only LocalDriver, S3Driver and GCSDriver support, but you can extend the drivers for Storage class if you implement DriverContract interface
220
191
221
192
``` ts
222
193
import { DriverContract } from ' @secjs/storage'
0 commit comments