func ReadString(fname string) (s string, err error) { err = file.Read(fname, func(fd *os.File) error { s, err = encodeio.ReadString(fd) return err }) return }
func ReadGZIP(fname string) (data []byte, err error) { err = file.Read(fname, func(fd *os.File) error { data, err = encodeio.ReadGZIP(fd) return err }) return }
func ReadCommenttedJSON(fname, comment string, v interface{}) error { var trim = func(line, delim []byte) []byte { if len(delim) > 0 && bytes.HasPrefix(bytes.TrimSpace(line), delim) { return nil } return line } return file.Read(fname, func(fd *os.File) error { bs, err := ioutil.ReadAll(fd) if err != nil { return err } bs = bytes2.MultipleLineOperate(bs, unsafe2.Bytes(comment), trim) return json.Unmarshal(bs, v) }) }
func ReadJSONWithComment(fname string, v interface{}) error { return file.Read(fname, func(fd *os.File) error { buf := bytes.NewBuffer(make([]byte, 0, 1024)) br := bufio.NewReader(fd) for { line, _, err := br.ReadLine() if err == io.EOF { if len(line) == 0 { break } } else if err != nil { return err } if !bytes.HasPrefix(bytes.TrimSpace(line), commentPrefix) { buf.Write(line) } } return encoding.JSON.Unmarshal(buf.Bytes(), v) }) }
func ReadJSON(fname string, v interface{}) error { return file.Read(fname, func(fd *os.File) error { return json.NewDecoder(fd).Decode(v) }) }
func ReadGOB(fname string, v interface{}) error { return file.Read(fname, func(fd *os.File) error { return gob.NewDecoder(fd).Decode(v) }) }
func Read(fname string, v interface{}, decoder encodeio.DecodeFunc) error { return file.Read(fname, func(fd *os.File) error { return encodeio.Read(fd, v, decoder) }) }
func Read(fname string, v interface{}, codec encoding.Codec) error { return file.Read(fname, func(fd *os.File) error { return codec.Decode(fd, v) }) }