@@ -48,11 +48,11 @@ module.exports = (context) => {
48
48
throw err
49
49
}
50
50
51
- if ( ! statters [ file . cid . codec ] ) {
51
+ if ( ! statters [ file . type ] ) {
52
52
throw new Error ( `Cannot stat codec ${ file . cid . codec } ` )
53
53
}
54
54
55
- return statters [ file . cid . codec ] ( file )
55
+ return statters [ file . type ] ( file )
56
56
}
57
57
58
58
return withTimeoutOption ( mfsStat )
@@ -61,7 +61,7 @@ module.exports = (context) => {
61
61
/** @type {Record<string, (file:any) => Stat> } */
62
62
const statters = {
63
63
/**
64
- * @param {any } file
64
+ * @param {import('ipfs-unixfs-exporter').RawNode } file
65
65
* @returns {Stat }
66
66
*/
67
67
raw : ( file ) => {
@@ -77,59 +77,46 @@ const statters = {
77
77
}
78
78
} ,
79
79
/**
80
- * @param {any } file
80
+ * @param {import('ipfs-unixfs-exporter').UnixFSFile } file
81
81
* @returns {Stat }
82
82
*/
83
- 'dag-pb' : ( file ) => {
84
- const blocks = file . node . Links . length
85
- const size = file . node . size
86
- const cumulativeSize = file . node . size
87
-
88
- /** @type {Stat } */
89
- const output = {
83
+ file : ( file ) => {
84
+ return {
90
85
cid : file . cid ,
91
86
type : 'file' ,
92
- size : size ,
93
- cumulativeSize : cumulativeSize ,
94
- blocks : blocks ,
87
+ size : file . unixfs . fileSize ( ) ,
88
+ cumulativeSize : file . node . size ,
89
+ blocks : file . unixfs . blockSizes . length ,
95
90
local : undefined ,
96
91
sizeLocal : undefined ,
97
- withLocality : false
92
+ withLocality : false ,
93
+ mode : file . unixfs . mode ,
94
+ mtime : file . unixfs . mtime
98
95
}
99
-
100
- if ( file . unixfs ) {
101
- output . size = file . unixfs . fileSize ( )
102
-
103
- // for go-ipfs compatibility
104
- if ( file . unixfs . type === 'hamt-sharded-directory' ) {
105
- output . type = 'directory'
106
- } else {
107
- output . type = file . unixfs . type
108
- }
109
-
110
- output . mode = file . unixfs . mode
111
-
112
- if ( file . unixfs . isDirectory ( ) ) {
113
- output . size = 0
114
- output . cumulativeSize = file . node . size
115
- }
116
-
117
- if ( output . type === 'file' ) {
118
- output . blocks = file . unixfs . blockSizes . length
119
- }
120
-
121
- if ( file . unixfs . mtime ) {
122
- output . mtime = file . unixfs . mtime
123
- }
96
+ } ,
97
+ /**
98
+ * @param {import('ipfs-unixfs-exporter').UnixFSDirectory } file
99
+ * @returns {Stat }
100
+ */
101
+ directory : ( file ) => {
102
+ return {
103
+ cid : file . cid ,
104
+ type : 'directory' ,
105
+ size : 0 ,
106
+ cumulativeSize : file . node . size ,
107
+ blocks : file . node . Links . length ,
108
+ local : undefined ,
109
+ sizeLocal : undefined ,
110
+ withLocality : false ,
111
+ mode : file . unixfs . mode ,
112
+ mtime : file . unixfs . mtime
124
113
}
125
-
126
- return output
127
114
} ,
128
115
/**
129
- * @param {any } file
116
+ * @param {import('ipfs-unixfs-exporter').ObjectNode } file
130
117
* @returns {Stat }
131
118
*/
132
- 'dag-cbor' : ( file ) => {
119
+ object : ( file ) => {
133
120
// @ts -ignore - This is incompatible with Stat object
134
121
// @TODO - https://github.com/ipfs/js-ipfs/issues/3325
135
122
return {
@@ -140,14 +127,14 @@ const statters = {
140
127
}
141
128
} ,
142
129
/**
143
- * @param {any } file
130
+ * @param {import('ipfs-unixfs-exporter').IdentityNode } file
144
131
* @returns {Stat }
145
132
*/
146
133
identity : ( file ) => {
147
134
return {
148
135
cid : file . cid ,
149
- size : file . unixfs . data . length ,
150
- cumulativeSize : file . unixfs . data . length ,
136
+ size : file . node . length ,
137
+ cumulativeSize : file . node . length ,
151
138
blocks : 0 ,
152
139
type : 'file' , // for go compatibility
153
140
local : undefined ,
0 commit comments