From 38a1391cc752391dd5af07df3b930a587f741e82 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..07f04bb9 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 uint64(readedBytes) == 0 { + return nil, errors.New("not enough bytes tor read") + } + currentlyReadedBytes += uint64(readedBytes) } + return data, nil }