以[] byte读取目录而不压缩目录

I am experimenting grpc for transferring large files and directories from server to clients. When I transfer a directory, I use the zip package to create a zip writer to create an archive of the directory, which is then transferred using grpc.

zipfile, err := os.Create(target)
zip.NewWriter(zipfile)

This works, but I was wondering if there's any convenient way to read a directory and its contents (files and sub-directories) into a []byte array for transfer over the wrire.

Your are free to use anything that implements io.Writer interface as destination of your zip archive zip.NewWriter

If you want it to be stored into byte slice and do not know the size of it beforehand I would suggest to use bytes.Buffer as your destination:

buffer := &bytes.Buffer{}
zip.NewWriter(buffer)
... do anything you need
resultBytesSlice := buffer.Bytes()