douyanpeng0748 2016-08-20 04:44
浏览 884


I have an io.Reader in Golang and I want to double-check that the size of its data is below a predetermined maximum before or while running io.Copy() to save it to disk using io.Writer.

Since the file data in io.Reader could theoretically be quite large, I want to minimize memory usage and processing here if avoidable.
I don't think there's a function that's like io.CopyLessThanOrEqualToThisManyBytesOrReturnError(), but I did notice that io.ReadFull() can do the opposite to return an error if not enough bytes are there to fill the provided buffer.

Does anyone have a solution to this?

To clarify, copying a fraction of the data is not OK. It either needs to fail if it's over the threshold, or work if it's under.

  • 写回答



      相关推荐 更多相似问题


      • ¥15 Quantlib求discount factors
      • ¥15 JS宏提取满足比率的字符区段
      • ¥20 webapi项目的XUnitTest单元测试怎么注入token和自写拦截器(filter)(语言-c#)
      • ¥15 exe和xml必须在一个文件夹才能打开exe文件
      • ¥15 房号如何排序,sql或算法
      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗