MCPcopy
hub / github.com/kopia/kopia / readInputFile

Method readInputFile

cli/command_benchmark_compression.go:54–81  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

52}
53
54func (c *commandBenchmarkCompression) readInputFile(ctx context.Context) ([]byte, error) {
55 f, err := os.Open(c.dataFile)
56 if err != nil {
57 return nil, errors.Wrap(err, "error opening input file")
58 }
59
60 defer f.Close() //nolint:errcheck
61
62 st, err := f.Stat()
63 if err != nil {
64 return nil, errors.Wrap(err, "stat error")
65 }
66
67 dataLength := st.Size()
68 if dataLength > defaultCompressedDataByMethod {
69 dataLength = defaultCompressedDataByMethod
70
71 log(ctx).Infof("NOTICE: The provided input file is too big, using first %v.", units.BytesStringBase2(dataLength))
72 }
73
74 data := make([]byte, dataLength)
75
76 if _, err := io.ReadFull(f, data); err != nil {
77 return nil, errors.Wrap(err, "error reading file")
78 }
79
80 return data, nil
81}
82
83type compressionBenchmarkResult struct {
84 compression compression.Name

Callers 1

runMethod · 0.95

Calls 5

BytesStringBase2Function · 0.92
OpenMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.65
SizeMethod · 0.45

Tested by

no test coverage detected