@@ -6,6 +6,7 @@ chai.use(require('dirty-chai'))
66const expect = chai . expect
77const path = require ( 'path' )
88const loadFixture = require ( 'aegir/fixtures' )
9+ const bufferStream = require ( './fixtures/buffer-stream' )
910
1011const {
1112 createMfs
@@ -40,15 +41,59 @@ describe('read', function () {
4041 } )
4142 } )
4243
43- it . skip ( 'reads a file with an offset' , ( ) => {
44+ it ( 'reads a file with an offset' , ( ) => {
45+ const path = `/some-file-${ Math . random ( ) } .txt`
46+ let data = Buffer . alloc ( 0 )
47+ const offset = 10
4448
49+ return mfs . write ( path , bufferStream ( 100 , {
50+ collector : ( bytes ) => {
51+ data = Buffer . concat ( [ data , bytes ] )
52+ }
53+ } ) , {
54+ create : true
55+ } )
56+ . then ( ( ) => mfs . read ( path , {
57+ offset
58+ } ) )
59+ . then ( ( buffer ) => expect ( buffer ) . to . deep . equal ( data . slice ( offset ) ) )
4560 } )
4661
47- it . skip ( 'reads a file with a length' , ( ) => {
62+ it ( 'reads a file with a length' , ( ) => {
63+ const path = `/some-file-${ Math . random ( ) } .txt`
64+ let data = Buffer . alloc ( 0 )
65+ const length = 10
4866
67+ return mfs . write ( path , bufferStream ( 100 , {
68+ collector : ( bytes ) => {
69+ data = Buffer . concat ( [ data , bytes ] )
70+ }
71+ } ) , {
72+ create : true
73+ } )
74+ . then ( ( ) => mfs . read ( path , {
75+ length
76+ } ) )
77+ . then ( ( buffer ) => expect ( buffer ) . to . deep . equal ( data . slice ( 0 , length ) ) )
4978 } )
5079
51- it . skip ( 'reads a file with an offset and a length' , ( ) => {
80+ it ( 'reads a file with an offset and a length' , ( ) => {
81+ const path = `/some-file-${ Math . random ( ) } .txt`
82+ let data = Buffer . alloc ( 0 )
83+ const offset = 10
84+ const length = 10
5285
86+ return mfs . write ( path , bufferStream ( 100 , {
87+ collector : ( bytes ) => {
88+ data = Buffer . concat ( [ data , bytes ] )
89+ }
90+ } ) , {
91+ create : true
92+ } )
93+ . then ( ( ) => mfs . read ( path , {
94+ offset,
95+ length
96+ } ) )
97+ . then ( ( buffer ) => expect ( buffer ) . to . deep . equal ( data . slice ( offset , offset + length ) ) )
5398 } )
5499} )
0 commit comments