@@ -48,11 +48,11 @@ module.exports = (context) => {
4848 throw err
4949 }
5050
51- if ( ! statters [ file . cid . codec ] ) {
51+ if ( ! statters [ file . type ] ) {
5252 throw new Error ( `Cannot stat codec ${ file . cid . codec } ` )
5353 }
5454
55- return statters [ file . cid . codec ] ( file )
55+ return statters [ file . type ] ( file )
5656 }
5757
5858 return withTimeoutOption ( mfsStat )
@@ -61,7 +61,7 @@ module.exports = (context) => {
6161/** @type {Record<string, (file:any) => Stat> } */
6262const statters = {
6363 /**
64- * @param {any } file
64+ * @param {import('ipfs-unixfs-exporter').RawNode } file
6565 * @returns {Stat }
6666 */
6767 raw : ( file ) => {
@@ -77,59 +77,46 @@ const statters = {
7777 }
7878 } ,
7979 /**
80- * @param {any } file
80+ * @param {import('ipfs-unixfs-exporter').UnixFSFile } file
8181 * @returns {Stat }
8282 */
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 {
9085 cid : file . cid ,
9186 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 ,
9590 local : undefined ,
9691 sizeLocal : undefined ,
97- withLocality : false
92+ withLocality : false ,
93+ mode : file . unixfs . mode ,
94+ mtime : file . unixfs . mtime
9895 }
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
124113 }
125-
126- return output
127114 } ,
128115 /**
129- * @param {any } file
116+ * @param {import('ipfs-unixfs-exporter').ObjectNode } file
130117 * @returns {Stat }
131118 */
132- 'dag-cbor' : ( file ) => {
119+ object : ( file ) => {
133120 // @ts -ignore - This is incompatible with Stat object
134121 // @TODO - https://github.com/ipfs/js-ipfs/issues/3325
135122 return {
@@ -140,14 +127,14 @@ const statters = {
140127 }
141128 } ,
142129 /**
143- * @param {any } file
130+ * @param {import('ipfs-unixfs-exporter').IdentityNode } file
144131 * @returns {Stat }
145132 */
146133 identity : ( file ) => {
147134 return {
148135 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 ,
151138 blocks : 0 ,
152139 type : 'file' , // for go compatibility
153140 local : undefined ,
0 commit comments