-- ************************************************************************
-- Script: ZIPLIST
-- Version: 0.1
-- Date: 2008-12-02
--
-- purpose:
-- returns list of files found in ZIP archive
--
-- requirements:
-- + Director 10 or older
-- + a read/write xtra: fileIO xtra, BinFile xtra or BinaryIO xtra
-- + a corresponding "interface script" from here:
-- http://dasdeck.de/staff/valentin/lingo/binary_file_interface/
--
-- usage:
-- put ziplist("c:\test.zip")
-- ************************************************************************
on ziplist fn
fp = fopen(fn, "rb")
fsize = fsize(fp)
fseek (fp, fsize-6)
data = fread(fp, 4)
pos = chartonum(data.char[1]) + 256*chartonum(data.char[2])+256*256*chartonum(data.char[3])+256*256*256*chartonum(data.char[4])
fseek (fp, pos)
filelist = []
magic = "PK"&numtochar(1)&numtochar(2)
repeat while true
if fread(fp, 4)<>magic then exit repeat
fseek(fp, 24, 1)
lenStr = fread(fp,2)
len = chartonum(lenStr.char[1]) + 256*chartonum(lenStr.char[2])
fseek(fp, 16, 1)
filelist.add(fread(fp, len))
end repeat
fclose(fp)
return filelist
end