Skip to content

Commit 2db7bbc

Browse files
tarutistrib
authored andcommitted
Support extending files in memoryfs truncate
1 parent 8a2434a commit 2db7bbc

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

memfs/memory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ func (f *file) Close() error {
273273
func (f *file) Truncate(size int64) error {
274274
if size < int64(len(f.content.bytes)) {
275275
f.content.bytes = f.content.bytes[:size]
276+
} else if more := int(size)-len(f.content.bytes); more > 0 {
277+
f.content.bytes = append(f.content.bytes, make([]byte, more)...)
276278
}
279+
277280
return nil
278281
}
279282

0 commit comments

Comments
 (0)