| 52 | } |
| 53 | |
| 54 | func (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 | |
| 83 | type compressionBenchmarkResult struct { |
| 84 | compression compression.Name |