doufeinai6081 2019-09-17 07:18
浏览 88
已采纳

如果我的类型作为流没有意义,我应该实现io.Reader / io.Writer吗?

Question regarding zip and io.Reader/io.Writer. As far as I understand, one of the purpose of io/Reader/io.Writer is streaming. But should I implement one of these if my type does not really make sense "as chunks"?

For more details:

Lets say I have this struct.

type MyZip struct {
    file1, file2 []byte
}

MyZip represents a particular structured zip. Let's say for example it represents a zip file containing exactly a file named file1 and a file named file2. MyZip has the responsibility of parsing a zip file to extract these two files into two []byte fields. It also should handle the other way around (turning these two []byte fields as two files named test1 and test2 archived into a zip file).

As far as I understand, the package archive/zip does not allow to decompress a zip file as a stream. We have to fully load the zip in memory or as a file and decompress afterwards.

So to refine my question, does it make sense for MyZip to implement io.Reader/io.Writer for reading/writing from/to the final zip file?

As said above, as I cannot extract the two files on the fly, I would have to add some sort of buffer to MyZip and just read/write from/to this buffer. So the zip would anyway be fully stored in memory before being streamed. Is it a counter indication for not using io.Reader/io.Writer?

Thanks a lot for shedding light!

  • 写回答

1条回答 默认 最新

    报告相同问题?

    相关推荐 更多相似问题

    悬赏问题

    • ¥15 想了2小时了,求解答
    • ¥15 python怎么自动填表、登录?
    • ¥15 python列表嵌套按条件合并
    • ¥15 VBA怎么把工作簿A中的第N列,复制到工作簿B中的第N列。
    • ¥20 除了狗屎npm, 推荐一些编写web应用的方式?
    • ¥30 如何对嵌套结构体进行动态内存分配
    • ¥15 为什么我使用mongotemplate聚合操作老是查不到数据,find查询就可以
    • ¥15 关于sprintf的几个问题
    • ¥15 不确定行列数的迷宫文件传入
    • ¥15 怎么解决kali linux从root文件夹里复制文件权限不够的问题