On 20 Sep 2016 9:03 a.m., "Robert Solomon" <drrob...@gmail.com> wrote: > > FileReadBuffer := make([]byte,ReadBufferSize); > for { // Repeat Until eof loop. > n,err := TargetFile.Read(FileReadBuffer); > if n == 0 || err == io.EOF { break } > check(err," Unexpected error while reading the target file on which to compute the hash,"); > hasher.Write(FileReadBuffer); > FileSize += int64(n); > } // Repeat Until
The problem you encounter is that .Read() isn't required to fill the buffer you give it, it can give you less than that. Handling that requires you to slice the result eg. hasher.Write(FileReadBuffer[:n]); But you should avoid calling Read() and Write() and instead use higher level functions like io.Copy() which will handle these low level details for you. Read the io package docs for more information. https://golang.org/pkg/io/ -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.