码迷,mamicode.com
首页 > 其他好文 > 详细

golang io需要牢记的几个点

时间:2016-06-07 13:05:22      阅读:309      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!