Files
gobngsdk/writer_binary.go
esilva 312d979be1 added some new API calls
mainly around getting the file size and data read for convenience for
other tools
2026-09-16 23:47:35 +01:00

47 lines
719 B
Go

package bngsdk
import (
"encoding/binary"
"os"
)
type OgBinWriter struct {
file *os.File
totalBytes int64
}
func NewOgBinWriter(path string) (*OgBinWriter, error) {
outputFile, err := os.Create(path)
if err != nil {
return nil, err
}
return &OgBinWriter{
file: outputFile,
}, nil
}
func (ogw *OgBinWriter) Close() error {
if ogw.file != nil {
return ogw.file.Close()
}
return nil
}
func (ogw *OgBinWriter) Write(data []byte) (int, error) {
err := binary.Write(ogw.file, binary.LittleEndian, data)
if err != nil {
return 0, err
}
nBytes := len(data)
ogw.totalBytes += int64(nBytes)
return nBytes, nil
}
func (ogw *OgBinWriter) GetTotalWritten() int64 {
return ogw.totalBytes
}