Skip to content

Commit abd840d

Browse files
authored
feat: init refactor (#10)
* feat: init refactor * refactor: remove config methods, tempDriver and changeDefaultDisk
1 parent 32c761d commit abd840d

File tree

9 files changed

+611
-182
lines changed

9 files changed

+611
-182
lines changed

README.md

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -155,68 +155,39 @@ await storage.move('folder/DASdsakdjas912831jhdasnm.txt', 'folder/test/move.txt'
155155

156156
### Subscribing configs of disks in runtime
157157

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
159159
160160
```ts
161+
// Using disk method approach
161162
// File created on storage/newAppFolder/file.txt
162163
storage
163-
.addConfig('root', Path.noBuild().storage('newAppFolder'))
164+
.disk('local', { root: Path.noBuild().storage('newAppFolder') })
164165
.put('file.txt', Buffer.from('Hello World'))
165166

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') })
170169

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
176175
```
177176

178177
### Using S3 or GCS disk
179178

180179
> You can use **s3** or **gcs** disk to make all this actions inside buckets
181180
182181
```ts
182+
// Saves to S3
183183
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!'))
215186
```
216187

217188
### Extending disks and drivers
218189

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
220191
221192
```ts
222193
import { DriverContract } from '@secjs/storage'

0 commit comments

Comments
 (0)