Re: archived data [message #54334 is a reply to message #54333] |
Tue, 05 June 2007 10:12   |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Jun 3, 10:54 am, Wox <nom...@hotmail.com> wrote:
> Hi All,
>
> I face the following situation: I'd like to do some online data
> processing (i.e. during measurements) using IDL. However the data is
> directly zipped by the acquisition system. Is it possible to read and
> search (like file_search) in a zip archive without spawning unzip and
> extract everything? Windows explorer does it, so it must be
> possible...
>
> I remember a similar question beeing posted here, but I couldn't find
> it.
>
> Thanks
I just threw this together. Your milage may vary:
function byte_to_hex, bytes
nbytes = n_elements(bytes)
hstr = string(bytes, format="(z2.2)")
vform = '(' + strtrim(nbytes,2) + 'A)'
hval = string( reverse(hstr),format=vform )
val = 0l
reads, hval, val, format="(z)"
return, val
end
function zipcontents, fname
endsig = '504b0506'
finfo = file_info(fname)
fsize = finfo.size
fdata = bytarr(fsize)
openr, lun, fname, /get_lun
readu, lun, fdata
free_lun, lun
fcode = '(' + strtrim(fsize,2) + 'z2.2)'
sdata = string(fdata, format=fcode)
fptr = strpos(sdata, endsig) / 2
fptr += 8
numentries = byte_to_hex( fdata[fptr:fptr+1] )
fptr += 8
cd_offset = byte_to_hex( fdata[fptr:fptr+3] )
fptr = cd_offset
contents = strarr(numentries)
for i=0l, numentries-1 do begin
fptr += 28
fnamelen = byte_to_hex( fdata[fptr:fptr+1] )
fptr += 2
extrafieldlen = byte_to_hex( fdata[fptr:fptr+1] )
fptr += 2
fcommentlen = byte_to_hex( fdata[fptr:fptr+1] )
fptr += 14
contents[i] = string(fdata[fptr:fptr+fnamelen-1])
fptr = fptr + fnamelen + extrafieldlen + fcommentlen
endfor
return, contents
end
|
|
|