Reduce file size
os.Truncate() function will reduce the file content upto N bytes passed in second parameter. In below example if size of test.txt file is more that 1Kb(100 byte) then it will truncate the remaining content.
Example
package main
import (
"log"
"os"
)
func main() {
err := os.Truncate("test.txt", 100)
if err != nil {
log.Fatal(err)
}
}
Most Helpful This Week
Go program to compress list of files into Zip file
Go program to read a text file character by character
Move a file from one location to another in Golang
Golang Changing permissions, ownership, and timestamps
Go program to read list of files inside Zip file
Go program to add or append content at the end of text file