github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/cbmem/io.go (about) 1 // Copyright 2016-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "encoding/binary" 9 "io" 10 "log" 11 ) 12 13 // readOneSize reads an entry of any type. This Size variant is for 14 // the console log only, though we know of no case in which it is 15 // larger than 1M. We really want the SectionReader as a way to ReadAt 16 // for the binary.Read. Any meaningful limit will be enforced by the kernel. 17 func readOneSize(r io.ReaderAt, i interface{}, o int64, n int64) { 18 err := binary.Read(io.NewSectionReader(r, o, n), binary.LittleEndian, i) 19 if err != nil { 20 log.Fatalf("Trying to read section for %T: %v", r, err) 21 } 22 } 23 24 // readOneSize reads an entry of any type, limited to 64K. 25 func readOne(r io.ReaderAt, i interface{}, o int64) { 26 readOneSize(r, i, o, 65536) 27 }