From 6c52bf096c01cde24c7985045b949409d965cbc9 Mon Sep 17 00:00:00 2001 From: Artur Albov Date: Thu, 31 Jan 2019 14:20:31 +0700 Subject: [PATCH] Fix import reader --- util/file.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/util/file.go b/util/file.go index fb863ff4..b3fc7d8c 100644 --- a/util/file.go +++ b/util/file.go @@ -18,12 +18,17 @@ func RootifyPath(path string) string { func ReadExactlyNBytes(reader io.Reader, n uint64) ([]byte, error) { data := make([]byte, n) - bytesReaded, err := reader.Read(data) - if err != nil { - return nil, err - } - if uint64(bytesReaded) != n { - return nil, errors.New("not enough bytes tor read") + currentlyReadedBytes := uint64(0) + for currentlyReadedBytes < n { + readedBytes, err := reader.Read(data[currentlyReadedBytes:n]) + if err != nil { + return nil, err + } + if readedBytes == 0 { + return nil, errors.New("not enough bytes tor read") + } + currentlyReadedBytes += uint64(readedBytes) } + return data, nil }