Skip to content

Commit 8a2434a

Browse files
tarutistrib
authored andcommitted
Add support for Truncate on files
1 parent 8067977 commit 8a2434a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

fs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,6 @@ type File interface {
140140
Lock() error
141141
// Unlock unlocks the file.
142142
Unlock() error
143+
// Truncate the file.
144+
Truncate(size int64) error
143145
}

memfs/memory.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ func (f *file) Close() error {
270270
return nil
271271
}
272272

273+
func (f *file) Truncate(size int64) error {
274+
if size < int64(len(f.content.bytes)) {
275+
f.content.bytes = f.content.bytes[:size]
276+
}
277+
return nil
278+
}
279+
273280
func (f *file) Duplicate(filename string, mode os.FileMode, flag int) billy.File {
274281
new := &file{
275282
name: filename,

test/mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,7 @@ func (*FileMock) Lock() error {
130130
func (*FileMock) Unlock() error {
131131
return nil
132132
}
133+
134+
func (*FileMock) Truncate(size int64) error {
135+
return nil
136+
}

0 commit comments

Comments
 (0)