Why Golang does not provide a copy file func ?

xuanbao · · 552 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>We all know that, for instance, we can provide a &#34;copy file&#34; function by opening a stream to the &#34;current&#34; file and write to a certain destination. But the question is, Why Golang does not provide a copy file func ? Even by wrapping the buffer &#34;in=&gt;out&#34; solution ?</p> <hr/>**评论:**<br/><br/>mwholt: <pre><p>File copy has tricky edge cases to consider that are best left up to the programmer to decide. (I used to wonder the same thing but after implementing a simple file copy myself I came to see why it&#39;s not in the standard lib.)</p> <p>For example, if you&#39;re copying a folder, and the destination has a file with the same name and path, do you overwrite or skip? Just think of all the various error messages and prompts you&#39;ve encountered while copying files with your OS - related to permissions, symlinks/shortcuts, etc. It&#39;s just not obvious how to handle a file copy and there is no &#34;standard&#34; way to do it.</p></pre>wbyte: <pre><p>To add to this, some filesystems provide non-standard syscalls for copying files efficiently. Some filesystems can support reflink-style copying (sharing data blocks between files until they differ) for example. It&#39;s up to the application to make use of those features if they choose, and doing so in the standard lib would be too cumbersome or make too many assumptions to be generally useful.</p></pre>Yojihito: <pre><blockquote> <p>For example, if you&#39;re copying a folder, and the destination has a file with the same name and path, do you overwrite or skip?</p> </blockquote> <p>Default is skip until overruled with code flag by the developer?</p></pre>bradfitz: <pre><p>See past discussion in the bug and the linked code reviews from the bug: <a href="https://github.com/golang/go/issues/8868">https://github.com/golang/go/issues/8868</a></p></pre>raff99: <pre><p>Anything wrong with io.Copy ?</p> <p>func Copy(dst Writer, src Reader) (written int64, err error)</p></pre>kurin: <pre><p>Doesn&#39;t handle metadata (e.g. how do I copy windows acls in Go?)</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

552 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传