Skip to content

archive.tar: reader feature#24995

Merged
spytheman merged 6 commits into
vlang:masterfrom
jorgeluismireles:archive_tar_read_feature
Jul 30, 2025
Merged

archive.tar: reader feature#24995
spytheman merged 6 commits into
vlang:masterfrom
jorgeluismireles:archive_tar_read_feature

Conversation

@jorgeluismireles

@jorgeluismireles jorgeluismireles commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

V code to read into memory selected sections of archives *.tar.gz.

Modules proposal

vlib/archive/tar/testdata/*
vlib/archive/tar/*
examples/tar_gz_reader.v

Go tar source code is in package archive/tar.

  • Decompress with/without chunks from HTTP or local.
  • Debug blocks fields and and push to an array to complete a given file content.
  • Manages long paths > 100 chars.
  • Stop early after reaching a target.

Example application

File: examples/tar_gz_reader.v

$ v run tar_gz_reader.v -h
tar_gz_reader 0.0.20250721
-----------------------------------------------
Usage: tar_gz_reader [options] [ARGS]

Description: Reads into memory selected sections of *.tar.gz. archives from https or home_dir.

Options:
  -u, --url <string>        archive *.tar.gz URL, default(https://github.com/vlang/v/archive/refs/tags/v0.1.3.tar.gz). Start name with file:/// for local
  -c, --chunks              decompress with chunks to reduce RAM usage, default(false)
  -d, --debug <int>         prints blocks: 1=other, 2:+dirs, 3=+files, 4=+data, default(0=silent)
  -m, --max_blocks <int>    maximum blocks to read, stop early. Default(0=read all)
  -f, --filename <string>   filename content complete print, stop early. Default(empty means none)
  -h, --help                display this help and exit
  --version                 output version information and exit

Download HTTPS (default archive)

Debug ignores, dirs, files. Stop early with file ending in CONDUCT.md and print all its rows:

$ v run tar_gz_reader.v -d 3 -f CONDUCT.md
OTHER  block:     1 global size:52 pax_global_header 
DIR    block:     3 v-0.1.3/ size:0
 FILE  block:     4 v-0.1.3/.gitattributes size:53
DIR    block:     6 v-0.1.3/.github/ size:0
 FILE  block:     7 v-0.1.3/.github/FUNDING.yml size:62
DIR    block:     9 v-0.1.3/.github/ISSUE_TEMPLATE/ size:0
 FILE  block:    10 v-0.1.3/.github/ISSUE_TEMPLATE/bug-report-for-v.md size:306
 FILE  block:    12 v-0.1.3/.github/ISSUE_TEMPLATE/bug_report.md size:220
 FILE  block:    14 v-0.1.3/.github/ISSUE_TEMPLATE/feature_request.md size:121
 FILE  block:    16 v-0.1.3/.gitignore size:46
 FILE  block:    18 v-0.1.3/.travis.yml size:251
 FILE  block:    20 v-0.1.3/CONDUCT.md size:24
--------------------------------------------------------------------------------
Download: https://github.com/vlang/v/archive/refs/tags/v0.1.3.tar.gz chunks:628 bytes=843828
Untar:    &max_blocks:3940 last_read:(block_number:21 path:v-0.1.3/CONDUCT.md special:no stop_early:true)
Content:  Path:v-0.1.3/CONDUCT.md bytes:24
--------------------------------------------------------------------------------
Be nice and respectful.

--------------------------------------------------------------------------------

A long list of blocks:

$ v run tar_gz_reader.v -u https://github.com/vlang/v/archive/refs/tags/weekly.2025.30.tar.gz -d 4 -c

...

OTHER  block: 92777 blank_1 continue  
OTHER  block: 92778 blank_2 end_archive  
--------------------------------------------------------------------------------
Download: https://github.com/vlang/v/archive/refs/tags/weekly.2025.30.tar.gz chunks:7781 bytes=10475545
Untar:    &max_blocks:0 last_read:(block_number:92778 path: special:blank_2 stop_early:false)
Content:  Path: bytes:0
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Download local

URL name should start with file:///, apps looks archive path from home directory.

Debug all, stop early at block 12_543 and verify filepaths can be longer than 100 chars.

$ v run tar_gz_reader.v -u file:///Downloads/v-weekly.2025.30.tar.gz -d 4 -m 12_543

...

 FILE  block: 12536 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template size:2628
  DATA block: 12537 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template len:512 pend:2116
  DATA block: 12538 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template len:512 pend:1604
  DATA block: 12539 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template len:512 pend:1092
  DATA block: 12540 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template len:512 pend:580
  DATA block: 12541 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template len:512 pend:68
  DATA block: 12542 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/acquire_release_volatile.template len:68 pend:0
 FILE  block: 12543 v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/atomic_load.h size:1686
--------------------------------------------------------------------------------
Download: file:///Downloads/v-weekly.2025.30.tar.gz chunks:0 bytes=10475545
Untar:    &max_blocks:92780 last_read:(block_number:12544 path:v-weekly.2025.30/thirdparty/libatomic_ops/atomic_ops/sysdeps/loadstore/atomic_load.h special:no stop_early:true)
Content:  Path: bytes:0
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23514

@JalonSolov

Copy link
Copy Markdown
Collaborator

While it's handy to have it handle gzip compressed tar files, building it in isn't really the best idea, since there are lots of other compression programs supported by tar... bzip, xz, etc., etc.

@jorgeluismireles

Copy link
Copy Markdown
Contributor Author

building it in isn't really the best idea

Totally agree, this tool is only the reader not the writer. If you know in advance the structure of your tar you can extract some parts saving time and space.

Comment thread examples/archive/tar_gz_reader.v Outdated
Comment thread vlib/archive/tar/reader.v Outdated
Comment thread vlib/archive/tar/reader.v Outdated
Comment thread vlib/archive/tar/reader.v Outdated
Comment thread vlib/archive/tar/reader.v Outdated
Comment thread vlib/archive/tar/reader.v Outdated
Comment thread vlib/archive/tar/reader.v Outdated

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit a8d75c1 into vlang:master Jul 30, 2025
72 of 74 checks passed
@jorgeluismireles jorgeluismireles deleted the archive_tar_read_feature branch September 14, 2025 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants