@@ -60,119 +60,4 @@ export class IpfsService {
60
60
const node = await this . ipfs ;
61
61
return await node . isOnline ( ) ;
62
62
}
63
-
64
- /**
65
- * @description Add a file with the given options
66
- * @param {IPFS_UTILS_TYPES.ImportCandidate } entry
67
- * @param {IPFS_ROOT_TYPES.AddOptions } [options={}]
68
- * @return {Promise<IPFS_ROOT_TYPES.AddResult> }
69
- */
70
- async add ( entry : IPFS_UTILS_TYPES . ImportCandidate , options : IPFS_ROOT_TYPES . AddOptions = { } ) : Promise < IPFS_ROOT_TYPES . AddResult > {
71
- console . log ( `Adding file ${ entry } ...` )
72
- console . log ( entry )
73
-
74
- const node = await this . ipfs
75
- const result = await node . add ( entry , options )
76
-
77
- this . _ipfsSource . next ( node ) ;
78
- console . log ( result )
79
- return result ;
80
- }
81
-
82
- /**
83
- * @description Add files with the given options
84
- * @param {IPFS_UTILS_TYPES.ImportCandidate[] } entries
85
- * @param {IPFS_ROOT_TYPES.AddAllOptions } [options={}]
86
- * @return {Promise<IPFS_ROOT_TYPES.AddResult[]> }
87
- */
88
- async addAll ( entries : IPFS_UTILS_TYPES . ImportCandidate [ ] , options : IPFS_ROOT_TYPES . AddAllOptions = { } ) : Promise < IPFS_ROOT_TYPES . AddResult [ ] > {
89
- console . log ( "Adding files..." )
90
- const results = [ ]
91
- const node = await this . ipfs
92
-
93
- for await ( const result of node . addAll ( entries , options ) ) {
94
- console . log ( result )
95
- results . push ( result )
96
- }
97
-
98
- this . _ipfsSource . next ( node ) ;
99
- return results ;
100
- }
101
-
102
- /**
103
- * @description Get file(s) of a given path
104
- * @param {IPFS_UTILS_TYPES.IPFSPath } ipfsPath
105
- * @param {IPFS_ROOT_TYPES.GetOptions } [options={}]
106
- * @param {boolean } [onlyFiles=true]
107
- * @return {Promise<Array<[IPFS_ROOT_TYPES.IPFSEntry, string]>> }
108
- */
109
- async get ( ipfsPath : IPFS_UTILS_TYPES . IPFSPath , options : IPFS_ROOT_TYPES . GetOptions = { } , onlyFiles = true ) :
110
- Promise < Array < [ IPFS_ROOT_TYPES . IPFSEntry , string ] > > {
111
- console . log ( `Returning file for ${ ipfsPath } ...` )
112
- const results = [ ] as Array < [ IPFS_ROOT_TYPES . IPFSEntry , string ] >
113
- const node = await this . ipfs
114
-
115
- for await ( const file of node . get ( ipfsPath , options ) ) {
116
- const content = [ ]
117
-
118
- if ( 'content' in file && file . content ) {
119
- for await ( const chunk of file . content ) {
120
- content . push ( chunk )
121
- }
122
- }
123
-
124
- if ( content . length > 0 || ! onlyFiles ) {
125
- results . push ( [ file , content . toString ( ) ] )
126
- }
127
- }
128
-
129
- console . log ( results )
130
- return results
131
- }
132
-
133
- /**
134
- * @description Read a file
135
- * @param {IPFS_UTILS_TYPES.IPFSPath } ipfsPath
136
- * @param {IPFS_ROOT_TYPES.CatOptions } [options={}]
137
- * @return {(Promise<string | null>) }
138
- */
139
- async cat ( ipfsPath : IPFS_UTILS_TYPES . IPFSPath , options : IPFS_ROOT_TYPES . CatOptions = { } ) :
140
- Promise < string | null > {
141
- console . log ( `Reading file for ${ ipfsPath } ...` ) ;
142
- const content = [ ]
143
- const node = await this . ipfs
144
-
145
- for await ( const chunk of node . cat ( ipfsPath , options ) ) {
146
- content . push ( chunk )
147
- }
148
-
149
- let result = null ;
150
-
151
- if ( content . length > 0 ) {
152
- result = content . toString ( ) ;
153
- }
154
-
155
- console . log ( content )
156
- return result ;
157
- }
158
-
159
- /**
160
- * @description List the file(s) and directory(ies) of a given path
161
- * @param {IPFS_UTILS_TYPES.IPFSPath } ipfsPath
162
- * @param {IPFS_ROOT_TYPES.ListOptions } [options={}]
163
- * @returns {Promise<Array<IPFS_ROOT_TYPES.IPFSEntry>> }
164
- */
165
- async ls ( ipfsPath : IPFS_UTILS_TYPES . IPFSPath , options : IPFS_ROOT_TYPES . ListOptions = { } ) :
166
- Promise < Array < IPFS_ROOT_TYPES . IPFSEntry > > {
167
- console . log ( `Listing files for ${ ipfsPath } ...` ) ;
168
- const result = [ ] ;
169
- const node = await this . ipfs
170
-
171
- for await ( const data of node . ls ( ipfsPath , options ) ) {
172
- result . push ( data )
173
- }
174
-
175
- console . log ( result )
176
- return result ;
177
- }
178
63
}
0 commit comments