checksumfile_updated

package
v0.0.0-...-2c42c2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package checksumfile can be used to persist data to a file so that it is never corrupted. It only works on unix* systems as it writes data to a temp file and uses rename syscall to move the file atomically. An example is:

    func main() {
    	data := []byte{"Hello World!"}
    	filename := "var/lib/kronos/nodeInfo" // directory in which file is
    	// stored should exist beforehand and have w and x permissions for user,
     	// otherwise write will fail.
    	if err :=  checksumfile-updated.Write(filename, data) {
    		panic(err)
    	}
    	read, err := checksumfile-updated.Read(filename)
    	if err != nil {
    		panic(err)
    	}
      fmt.Println(read)
    }

	Package checksumfile is a generated protocol buffer package.

	It is generated from these files:
		kronos/checksumfile/fileextent.proto

	It has these top-level messages:
		FileExtent

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthFileextent = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowFileextent   = fmt.Errorf("proto: integer overflow")
)
View Source
var ErrChecksumMismatch = errors.New("checksum and data don't match")

ErrChecksumMismatch is returned when checksum and data don't match for a file

Functions

func Read

func Read(filename string) ([]byte, error)

Read reads data written to filename using the Write function. It returns an error if the checksums don't match or file doesn't exist.

func Write

func Write(filename string, p []byte) error

Write writes p to filename along with its checksum in a binary format. This data can be read using the Read function. Write returns an error if data could not be completely written for some reason. It never corrupts the existing file.

Types

type FileExtent

type FileExtent struct {
	Checksum []byte `protobuf:"bytes,1,opt,name=Checksum,proto3" json:"Checksum,omitempty"`
	Data     []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"`
}

func (*FileExtent) Descriptor

func (*FileExtent) Descriptor() ([]byte, []int)

func (*FileExtent) Marshal

func (m *FileExtent) Marshal() (dAtA []byte, err error)

func (*FileExtent) MarshalTo

func (m *FileExtent) MarshalTo(dAtA []byte) (int, error)

func (*FileExtent) ProtoMessage

func (*FileExtent) ProtoMessage()

func (*FileExtent) Reset

func (m *FileExtent) Reset()

func (*FileExtent) Size

func (m *FileExtent) Size() (n int)

func (*FileExtent) String

func (m *FileExtent) String() string

func (*FileExtent) Unmarshal

func (m *FileExtent) Unmarshal(dAtA []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL