I have a function which splits data and returns slice of subslices:
(buf []byte, lim int) [][]byte
Obviously I get an error if I do:
n, err = out.Write(split(buf[:n], 100))
The error:
cannot convert split(buf[:n], 100) (type [][]byte) to type []byte
How do I convert [][]byte
to []byte
?
Edit based on @Wishwa Perera: https://play.golang.org/p/nApPAYRV4ZW
Since you are splitting buf
into chunks
, you can pass them individually to Write
by looping over the result of split
.
for _, chunk := range split(buf[:n], 100) {
if _, err := out.Write(chunk); err != nil {
panic(err)
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments