- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我是一名刚毕业的 SWE,正在学习 Go(并且喜欢它)。
我正在为维基百科转储文件构建一个解析器——基本上是一个巨大的 bzip2 压缩 XML 文件(~50GB 未压缩)。
我想同时做流式解压和解析,听起来很简单。对于减压,我这样做:
inputFilePath := flag.Arg(0)
输入阅读器 := bzip2.NewReader(输入文件)
然后将读取器传递给 XML 解析器:
解码器 := xml.NewDecoder(inputFile)
但是,由于解压缩和解析都是昂贵的操作,我想让它们在单独的 Go 例程上运行以利用额外的核心。我将如何在 Go 中执行此操作?
我唯一能想到的是将文件包装在一个 chan []byte 中,并实现 io.Reader 接口(interface),但我认为可能有一种内置的方式(和更清晰的)来实现它。
有没有人做过这样的事情?
谢谢!曼纽尔
最佳答案
您可以使用 io.Pipe , 然后使用 io.Copy将解压后的数据推送到管道中,并在另一个 goroutine 中读取:
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"sync"
)
func main() {
rawJson := []byte(`{
"Foo": {
"Bar": "Baz"
}
}`)
bzip2Reader := bytes.NewReader(rawJson) // this stands in for the bzip2.NewReader
var wg sync.WaitGroup
wg.Add(2)
r, w := io.Pipe()
go func() {
// write everything into the pipe. Decompression happens in this goroutine.
io.Copy(w, bzip2Reader)
w.Close()
wg.Done()
}()
decoder := json.NewDecoder(r)
go func() {
for {
t, err := decoder.Token()
if err != nil {
break
}
fmt.Println(t)
}
wg.Done()
}()
wg.Wait()
}
关于xml - GoLang : Decompress bz2 in on goroutine, 在其他协程中消费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36228655/
我一直在尝试导入名为 Winter Forest Envoriment 的 Assets ,每次单击导入时都会出现错误“导入包失败,出现错误:无法解压缩包UnityEngine.GUIUtility:
我想编写一个函数,它接受一个压缩字符串并输出解压缩字符串。 像 a2b2c3 这样的压缩字符串解压字符串为 aabbccc更多的例子是 `a` -> `a` `ab12` -> `abbbbbbbbb
我正在尝试使用 Swift 压缩包解压缩 lz4 压缩的 png 图像,但代码以零大小退出。 我的代码如下,解压后的文件预计为240Kb。 [更新 2] 我在 Apple 的文档中偶然发现了这一点:
我正在尝试使用 kafka-python。它要求安装 Snappy。所以我安装它 pip 安装 snappy pip 安装 python_snappy-0.5.2-cp36-cp36m-win_amd
我正在尝试解压缩 MySQL 的 COMPRESS 函数返回的值: SQLQuery query = session .createSQLQuery("SELECT ID, C
我正在尝试使用 Go 创建压缩字符串池。这是我的代码 - http://play.golang.org/p/T5usLfU0fA 我无法解压用 compress/lzw 包压缩的 bin。 lzw.W
我读过这篇 SO post无济于事。 我正在尝试解压缩来自 URL 的 .gz 文件。 url_file_handle=StringIO( gz_data ) gzip_file_handle=gzi
本文整理了Java中loci.formats.codec.ZlibCodec.decompress()方法的一些代码示例,展示了ZlibCodec.decompress()的具体用法。这些代码示例主要
在 ubuntu 19.04 上安装 Cassandra 3.11 版本后,一旦我启动命令 cqlsh,我就会收到以下错误 root@dnilesh:/etc/cassandra# cqlsh Con
我想将一些字节数据插入到 mysql VARBINARY 列中。数据很大,所以我想以压缩的方式存储它。 我正在使用 Percona 5.6 Mysql。我想用Java模拟mysql的COMPRESS函
我可以在python中解压从mysql压缩的数据吗? MySQL 5.6 select to_base64(compress("test")); 来自mysql的结果 BAAAAHicK0ktLgEA
http://php.net/manual/en/phar.decompress.php decompress(); // creates /path/to/my.phar ?> $p2 第一次用在代
我使用 Pillow 库创建缩略图。我必须创建很多,实际上超过 10.000 程序运行良好,但在处理大约 1.500 后,出现以下错误: Traceback (most recent call
我正在尝试使用 LzmaLib带有缓冲区的 LzmaCompress() 和 LzmaDecompress(),改编提供的示例 here . 我正在测试一个 ~3MB 的缓冲区,压缩函数似乎工作正常(
我是一名刚毕业的 SWE,正在学习 Go(并且喜欢它)。 我正在为维基百科转储文件构建一个解析器——基本上是一个巨大的 bzip2 压缩 XML 文件(~50GB 未压缩)。 我想同时做流式解压和解析
我有一个从MySQL表中获取名称(字符串)和值(byte[])的查询。查询都在执行,因为如果我在最后一行放上断点,我就可以查看数据数据表,并看到填充了名称字段的记录。但是,值字段为空。。如果我从查询中
本文整理了Java中net.spy.memcached.transcoders.WhalinV1Transcoder.decompress()方法的一些代码示例,展示了WhalinV1Transcod
本文整理了Java中net.spy.memcached.transcoders.WhalinTranscoder.decompress()方法的一些代码示例,展示了WhalinTranscoder.d
本文整理了Java中com.github.luben.zstd.Zstd.decompress()方法的一些代码示例,展示了Zstd.decompress()的具体用法。这些代码示例主要来源于Gith
本文整理了Java中io.airlift.compress.zstd.ZstdDecompressor.decompress()方法的一些代码示例,展示了ZstdDecompressor.decomp
我是一名优秀的程序员,十分优秀!