This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const exporter = require('ipfs-unixfs-engine').exporter
4
4
const pull = require ( 'pull-stream/pull' )
5
5
const collect = require ( 'pull-stream/sinks/collect' )
6
6
const waterfall = require ( 'async/waterfall' )
7
+ const UnixFs = require ( 'ipfs-unixfs' )
7
8
const {
8
9
traverseTo
9
10
} = require ( './utils' )
@@ -30,9 +31,16 @@ module.exports = (ipfs) => {
30
31
parents : false
31
32
} , done ) ,
32
33
( result , done ) => {
34
+ const node = result . node
35
+ const meta = UnixFs . unmarshal ( node . data )
36
+
37
+ if ( meta . type !== 'file' ) {
38
+ return done ( new Error ( `Error: ${ path } was not a file` ) )
39
+ }
40
+
33
41
waterfall ( [
34
42
( next ) => pull (
35
- exporter ( result . node . multihash , ipfs . _ipld , {
43
+ exporter ( node . multihash , ipfs . _ipld , {
36
44
offset : options . offset ,
37
45
length : options . length
38
46
} ) ,
Original file line number Diff line number Diff line change @@ -145,6 +145,15 @@ describe('read', function () {
145
145
. then ( ( result ) => method . collect ( result ) )
146
146
. then ( ( buffer ) => expect ( buffer ) . to . deep . equal ( data . slice ( offset , offset + length ) ) )
147
147
} )
148
+
149
+ it ( 'refuses to read a directory' , ( ) => {
150
+ const path = '/'
151
+
152
+ return method . read ( path )
153
+ . catch ( error => {
154
+ expect ( error . message ) . to . contain ( 'was not a file' )
155
+ } )
156
+ } )
148
157
} )
149
158
} )
150
159
} )
You can’t perform that action at this time.
0 commit comments