On 7/22/2018 2:26 AM, WJG wrote:
Here is an example of reading a compressed file (.gz) line-by-line --
just like you would read an uncompressed file. We simply attach
'gunzip' to the open channel (inFile) if the extention is .gz and place
the channel in 'binary mode' using 'fconfigure'.
1 #######################
2 # OPEN, input file (READ-ONLY)
3 #######################
4 set inFile [open $my_file r]
5 # attach uncompress (gunzip) method if input file is in *.gz format:
6 if { [string equal [file extension $my_file] ".gz"] } {
7 fconfigure $inFile -translation binary
8 zlib push gunzip $inFile
9 }
10
11 while { [gets $inFile line] >= 0 } {
12 <whatever you want here>
13 }
14
15 close $inFile
16
Line 4: Open a file for read access.
Line 6-9: Check file extension and add "zlib push gunzip" to the open
channel if extension is ".gz"
Line 11-13 Read the file line-by-line just like you would if it was not
compressed.
Line 12: Insert your code here. Example: puts $line