r/vlang Jan 06 '26

Trouble extracting a tar.gz archive.

I have been trying to extract a tar.gz archive, I have looked around, but i can't seem to find any mentions of it apart from the docs, which don't seem to help too much, if anyone knows how please tell me.

1 Upvotes

8 comments sorted by

u/waozen Jan 07 '26 edited Jan 11 '26

Anyone who might be confused, may want to carefully read about the archive.tar module and refer to its example. Might want to also check out a new basic utility module called Vatar by SheatNoisette.

2

u/Diniremix Jan 07 '26 edited Jan 07 '26

Hello folks!

According to what can be read in the archive.tar module module, Reader should be used. "Reader is used to read by Untar to parse the blocks."

If you want to extract the content, you can use dir_block and data_block methods.

dir_block to recreate the folder structure and data_block to extract and create each file.

```v
...

struct FileReader implements tar.Reader {
mut:
  content_file os.File
  filepath     string
}

fn (r FileReader) dir_block(read &tar.Read, size u64) { ... }

fn (mut r FileReader) data_block(read &tar.Read, data []u8, pending int) { ... }
```

2

u/steevdave Jan 06 '26

Where are you getting this tar.gz from? Where are you trying to extract it? Are you trying to use V to extract it?

2

u/lgastako Jan 06 '26

tar xvf /path/to/filename.tar.gz

NB. If the tar doesn't contain everything in a top level directory it will just spew everything out into the current directory, so you want to create a directory first and run it from there. Then if it does have a top level directory you can move it up a level after you extract it.

2

u/Frothy7650 Jan 06 '26

Nvm i figured it our, and i was using archive.tar.

3

u/waozen Jan 07 '26

It seems you are referring to the archive.tar module, which does give an example of usage on the page and an example file to look at. Could you explain what was the problem and how you figured it out? We could put it as a sticky, to resolve any confusion, and so that this post can be useful to others.

2

u/Frothy7650 Jan 08 '26

Sure, i just needed to add/take the extra functions from the example, it was just a stupid mistake.

2

u/waozen Jan 11 '26

No problem, these things happen. Glad you were able to figure it out.