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
Create an empty file
Go program to read a text file character by character
Go program to Create directory or folder if not exist
Get file information in Golang
Golang program to delete a specific file
Go program to compress list of files into Zip file
Go program to read list of files inside Zip file
Golang Changing permissions, ownership, and timestamps
Move a file from one location to another in Golang
Go program to extracting or unzip a Zip format file