MCPcopy
hub / github.com/tinylib/msgp / ReadFile

Function ReadFile

msgp/file.go:22–38  ·  view source on GitHub ↗

ReadFile reads a file into 'dst' using a read-only memory mapping. Consequently, the file must be mmap-able, and the Unmarshaler should never write to the source memory. (Methods generated by the msgp tool obey that constraint, but user-defined implementations may not.) Reading and writing through

(dst Unmarshaler, file *os.File)

Source from the content-addressed store, hash-verified

20// files are best read and written using
21// the ordinary streaming interfaces.
22func ReadFile(dst Unmarshaler, file *os.File) error {
23 stat, err := file.Stat()
24 if err != nil {
25 return err
26 }
27 data, err := syscall.Mmap(int(file.Fd()), 0, int(stat.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
28 if err != nil {
29 return err
30 }
31 adviseRead(data)
32 _, err = dst.UnmarshalMsg(data)
33 uerr := syscall.Munmap(data)
34 if err == nil {
35 err = uerr
36 }
37 return err
38}
39
40// MarshalSizer is the combination
41// of the Marshaler and Sizer

Callers

nothing calls this directly

Calls 2

adviseReadFunction · 0.70
UnmarshalMsgMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…