github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/file/empty.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package file
     6  
     7  import "os"
     8  
     9  // Empty is a shortcut function to seek to the beginning
    10  // of a file and truncate it to 0. It does not call
    11  // file.Sync though, making all operations in-memory only.
    12  func Empty(file *os.File) (err error) {
    13  	if _, err = file.Seek(0, 0); err != nil {
    14  		return
    15  	}
    16  	if err = file.Truncate(0); err != nil {
    17  		return
    18  	}
    19  	return
    20  }