Tcl Library Source Code

View Ticket
Login
Ticket UUID: 3438f804e41b67d469fd364087457d4c718d4f5b
Title: Add progress bar to the tar package
Type: RFE Version: 0.15
Submitter: anonymous Created on: 2025-10-06 19:42:53
Subsystem: tar Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2025-10-06 19:42:53
Resolution: None Closed By: nobody
    Closed on:
Description:
The code below is a minor adaption of the tar::create procedure. It adds the option -progress <name of callback function> that will update a progress bar.

proc ::tar::create {tar files args} {
    set dereference 0
    set chan 0
    set gzip 0
    set progress ""
    parseOpts {dereference 0 chan 0 gzip 0 progress 1} $args

    lassign [SetupCreation $chan $gzip $tar] fh pos

    set files [recurseDirs $files $dereference]
    if {$progress!=""} {
        set count [llength $files]
        eval [concat $progress $count 0]
        set i 0
    }
    foreach x $files {
        writefile $x $fh $dereference $x
        if {$gzip} {
            chan configure $fh -flush sync
        }
        if {$progress!=""} {
            incr i
            eval [concat $progress $count $i]
        }
    }
    if {$progress!=""} {
        eval [concat $progress 0 0]
    }
    puts -nonewline $fh [string repeat \x00 1024]

    Close $fh $pos $chan $gzip
    return $tar
}