@@ -6,6 +6,7 @@ chai.use(require('dirty-chai'))
6
6
const expect = chai . expect
7
7
const path = require ( 'path' )
8
8
const loadFixture = require ( 'aegir/fixtures' )
9
+ const bufferStream = require ( './fixtures/buffer-stream' )
9
10
10
11
const {
11
12
createMfs
@@ -40,15 +41,59 @@ describe('read', function () {
40
41
} )
41
42
} )
42
43
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
44
48
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 ) ) )
45
60
} )
46
61
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
48
66
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 ) ) )
49
78
} )
50
79
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
52
85
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 ) ) )
53
98
} )
54
99
} )
0 commit comments