首页 > 其他 > 详细

golang io需要牢记的几个点

时间:2016-06-07 13:03:05      阅读:176      评论:0      收藏:0      [点我收藏+]

对于Reader比较麻烦需要记住以下:

When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call

对于Write比较简单需要记住一下:

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-nil error if it returns n < len(p). Write must not modify the slice data, even temporarily.

对于ByteReader:就是一个字节一个字节的读

buio是对io的上层封装,他处理了一些常规错误情况等,另外读取支持读取到遇到某个字节为止,等等,还有一些其他很常用的功能。

golang io需要牢记的几个点

原文:http://www.cnblogs.com/anjianliang/p/5566155.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!