[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: creating a zip file
- From: Joshua Jensen <jjensen@...>
- Date: Tue, 26 May 2009 14:46:28 -0600
----- Original Message -----
From: Marco Antonio Abreu
Date: 5/26/2009 2:00 PM
I need to create a compacted file (zip, gzip, bzip or tar.gz) with
some files inside it from a Lua script on Windows. I look for LuaZip,
but it does not create zip files, only read them.
What is the best solution for my need?
The LuaPlus module vdrive does this very well. Find it at
svn://svn.luaplus.org/LuaPlus/work51/Src/Modules/vdrive. Unfortunately,
it currently uses LuaPlus APIs and is not directly compatible with
lua-5.1.dll. However, it shouldn't take too long to just use the Lua APIs.
It supports zip file creation, file erasing/renaming/insertion, and even
lists of files provided to the ProcessFileList() function which, in
turn, creates a zip with the files in the order specified. It also
supports encryption, although the encryption is not compatible with Winzip.
Josh
drive = vdrive.VirtualDrive() - Create virtual drive
time = vdrive.AdjustTime_t(timeToAdjust) - Adjusts a timestamp to zip format
Drive commands:
opened = drive:Create(fileName [, defaultPassword])
opened = drive:Open(fileName [, defaultPassword])
drive:Close()
drive:Flush()
vfile = drive:FileCreate(fileName,
compressionMethod:0,8{compressed}, time_t fileTime)
vfile = drive:FileOpen(fileName)
drive:FileCloseAll()
bool ret = drive:FileErase(fileName)
bool ret = drive:FileRename(oldFileName, newFileName)
bool ret = drive:FileInsert(srcFileName,
destVirtualFileHandleName, compressionMethod:0,8{compressed}, time_t
fileTime)
bool ret = drive:FileExtract(srcVirtualFileHandleName, destFileName)
drive:Pack(fileNameTable)
drive:ProcessFileList(fileNameTable|fileListFileName)
string fileName = drive:GetFileName()
int entryCount = drive:GetFileEntryCount()
FileEntry fileEntry = drive:GetFileEntry(index)
FileEntry fileEntry = drive:FindFileEntry(fileName)
FileEntry =
{
string FileName
time_t TimeStamp
DWORD CRC
DWORD Offset
DWORD Size
DWORD UncompressedSize
DWORD CompressedSize
DWORD CompressionMethod
}
int entryIndex = drive:GetFileEntryIndex(fileName)
File commands:
string fileName = drive:FileGetFileName(vfile)
long position = drive:FileGetPosition(vfile)
drive:FileSetLength(vfile, newLength)
long len = drive:FileGetLength(vfile)
buffer = drive:FileRead(vfile, optionalSize) If 0, the whole
file reads in.
drive:FileWrite(vfile, buffer, optionalSize) If 0, the whole
buffer writes out.
drive:Close(vfile)