Skip to content

Commit a5e16bd

Browse files
authored
Merge pull request #31 from SecJS/feat/len-add-move-copy
feat: Add move and copy methods to File and Folder classes
2 parents 29dae3a + 26096e0 commit a5e16bd

File tree

9 files changed

+1324
-123
lines changed

9 files changed

+1324
-123
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const nonExistentFile = new File('path/to/nonExistent/file.txt', Buffer.from('Fi
5555
// Now existentFile and nonExistentFile instances are created, but not loaded/created
5656

5757
// using load here because the file already exists, if using create, would generate an exception
58-
// property withContent if true, will save the file content in the instance, Be careful with big files
5958
existentFile.loadSync({ withContent: true })
59+
// property withContent if true, will save the file content in the instance, Be careful with big files
6060
nonExistentFile.createSync().loadSync({ withContent: true })
6161

6262
// now the files will have this properties
@@ -75,8 +75,16 @@ console.log(existentFile.getContentSync()) // Some Buffer instance
7575
// you can use toJSON method to get the instance informations in JSON
7676
console.log(existentFile.toJSON()) // { ...infos }
7777

78+
// you can make a copy from existentFile using copy
79+
console.log(existentFile.copySync('path/to/copy.txt'))
80+
81+
// you can move existentFile to other path using move
82+
console.log(existentFile.moveSync('path/to/move.txt'))
83+
7884
// File uses readable streams in async methods to not block the event loop when handling huge files content
7985
await existentFile.load()
86+
await existentFile.copy()
87+
await existentFile.move()
8088
await existentFile.remove()
8189
await existentFile.create()
8290
await existentFile.getContent()
@@ -99,11 +107,10 @@ const nonExistentFolder = new Folder('path/to/nonExistent/folder')
99107
// Now existentFolder and nonExistentFolder instances are created, but not loaded/created
100108

101109
// using load here because the file already exists, if using create, would generate an exception
110+
existentFolder.loadSync({ withSub: true, withFileContent: false })
102111

103112
// property withSub if true, will load files and subFolders from the folder
104113
// property withFileContent if true, will get the content of all files in the folder, Be careful with big files
105-
106-
existentFolder.loadSync({ withSub: true, withFileContent: false })
107114
nonExistentFolder.createSync().loadSync({ withSub: true, withFileContent: true })
108115

109116
// now the folders will have this properties
@@ -118,6 +125,12 @@ existentFolder.removeSync() // void
118125
// you can use toJSON method to get the instance informations in JSON
119126
console.log(existentFolder.toJSON()) // { ...infos }
120127

128+
// you can make a copy from existentFolder using copy
129+
console.log(existentFolder.copySync('path/to/copy'))
130+
131+
// you can move existentFolder to other path using move
132+
console.log(existentFolder.moveSync('path/to/move'))
133+
121134
// you can use getFilesByPattern method to get all files in the folder that match some pattern
122135
// if recursive is true, will go inside subFolders too
123136
const recursive = true
@@ -128,6 +141,8 @@ console.log(existentFolder.getFoldersByPattern('path/to/**/folder', recursive))
128141

129142
// Folder uses readable streams in async methods to not block the event loop when handling huge files content
130143
await existentFolder.load()
144+
await existentFolder.copy()
145+
await existentFolder.move()
131146
await existentFolder.remove()
132147
await existentFolder.create()
133148
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"description": "",
55
"license": "MIT",
66
"author": "João Lenon",

0 commit comments

Comments
 (0)