本文介绍了阅读xz文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在go程序中阅读文件?当我尝试使用。
- Try another library, perhaps one that uses cgo. I see two here.
- Use cgo directly/make your own lib.
- Use the xz executable.
选项三比听起来容易。这里是我会用的:
Option three is easier than it sounds. Here is what I would use:
func xzReader(r io.Reader) io.ReadCloser {
rpipe, wpipe := io.Pipe()
cmd := exec.Command("xz", "--decompress", "--stdout")
cmd.Stdin = r
cmd.Stdout = wpipe
go func() {
err := cmd.Run()
wpipe.CloseWithError(err)
}()
return rpipe
}
可运行代码:
这篇关于阅读xz文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!