admin管理员组文章数量:1389758
I'm new to Odin and am having some doubts on how to read a large Gzip file.
I've managed to reach the followng point where I load the to a bytes.Buffer. But assuming the gziped file is a text file I'm not sure how I would read it line by line.
buf_gzip := bytes.Buffer{}
defer bytes.buffer_destroy(&buf_gzip)
// Create a gzip reader
gz_err := gzip.load_from_file("example.gzip", &buf_gzip)
if gz_err != nil {
fmt.eprintf("Error loading gzip: %v\n", gz_err)
return
}
And I've later tried to read the gzip buffer content as if it would be a file without success.
r: bufio.Reader
buffer: [2048]byte
bytes.buffer_read_from(&buf_gzip, bufio.reader_to_stream(&r))
defer bufio.reader_destroy(&r)
for {
line, err := bufio.reader_read_string(&r, '\n', context.allocator)
if err != nil {
break
}
defer delete(line, context.allocator)
fmt.println(line)
}
I'm new to Odin and am having some doubts on how to read a large Gzip file.
I've managed to reach the followng point where I load the to a bytes.Buffer. But assuming the gziped file is a text file I'm not sure how I would read it line by line.
buf_gzip := bytes.Buffer{}
defer bytes.buffer_destroy(&buf_gzip)
// Create a gzip reader
gz_err := gzip.load_from_file("example.gzip", &buf_gzip)
if gz_err != nil {
fmt.eprintf("Error loading gzip: %v\n", gz_err)
return
}
And I've later tried to read the gzip buffer content as if it would be a file without success.
r: bufio.Reader
buffer: [2048]byte
bytes.buffer_read_from(&buf_gzip, bufio.reader_to_stream(&r))
defer bufio.reader_destroy(&r)
for {
line, err := bufio.reader_read_string(&r, '\n', context.allocator)
if err != nil {
break
}
defer delete(line, context.allocator)
fmt.println(line)
}
Share
Improve this question
edited Mar 17 at 23:48
Miguel Silva
asked Mar 17 at 1:02
Miguel SilvaMiguel Silva
11 bronze badge
1
- 1 done :) thank you – Miguel Silva Commented Mar 17 at 23:49
1 Answer
Reset to default 0After trial and error I managed to read the content like so. Hope this helps anyone in the future
r: bufio.Reader
r_buffer: [2048]byte
bufio.reader_init_with_buf(&r, bytes.buffer_to_stream(&buf_gzip), r_buffer[:])
defer bufio.reader_destroy(&r)
for {
line, err := bufio.reader_read_string(&r, '\n', context.allocator)
if err != nil {
break
}
defer delete(line, context.allocator)
line = strings.trim_right(line, "\r")
fmt.println(line)
}
本文标签: OdinRead a GZip fileStack Overflow
版权声明:本文标题:Odin - Read a GZip file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744582459a2614002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论