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
Add a comment  | 

1 Answer 1

Reset to default 0

After 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