Hi,
i have the following problem.
I want to read the contents of a .zip into an array/slice.
For small data this works fine, however, as soon as i want to read more than 32769 bytes,
it doesn't work the way i want to.
The read() only reads up to a maximum of ~32kbyte and i can't pass the old slice to a new call
of read, without the old data getting overriden, since i don't find how to add an offset.
Of course i could read into multiple slices and then copy their contents into a bigger slice, however,
this feels kinda unnecessary copy-work.
Is there a better way around it?
The way i do it now:
var data_hash map[string]*zip.File
func GetData(name string) *[]byte {
file, ok := data_hash[name]
if !ok {
log.Panic("File not found: \"" + name + "\"")
}
zip.NewReader()
reader, err := file.Open()
if err != nil {
log.Panicf("Could not read file \"%s\": %v", name, err)
}
defer reader.Close()
size := file.UncompressedSize
buffer := make([]byte, size)
n, err := reader.Read(buffer)
if err != nil {
log.Panicf("Failed to read file \"%s\": %v", name, err)
}
if n != int(size) {
//This is what happens if the file is too big
//I want to do something like: reader.Read(buffer + n)
log.Panicf("Failed to read file \"%s\": File has wrong size.", name)
}
return &buffer
}