How to decode .gz files using Microsoft Access VBA? - vba

I have some files which need reading using Access / VBA. They are compressed using ".gz" compression. How can I read those files in?
I figure this must be a solved problem but alas can't find anything. Command-line would be one option but it would involve the users of the VBA application having to have particular tools installed. Perhaps there is a library I can just include, which I can then ship with my VBA application (.accdr)?

There are quite a few libraries around, however, probably the most popular is zlib. A nice example using zlib, albeit written in VB6 (which shouldn't be too difficult to convert to VBA) is located here. One nice point about zlib is that it doesn't need registering (i.e. REGSVR*), so you should be able to drop it into the same folder as your DB (or even embed it into the DB then extract it automatically).

Related

How to put files inside files

MS Word's .docx files contain a bunch of .xml files.
Setup.exe files spit out hundreds of files that a program uses.
Zips, rars etc also hold lots of compressed stuff.
So how are they made? What does MS Word or another program that produces these files have to do to put files inside files?
When I looked this up I just got a bunch of results about compression, but let's say I wanted to make a program that 'wraps' files inside a file without making the final result any smaller. What would I even have to write?
I'm not asking/expecting any source code that does this, I just need a pointer. Is there something you think I'm misunderstanding based on what I've asked here?
Even a simple link to an article or some documentation would be greatly appreciated.
Ok, I'll just come up with some headers for ordinary files and write them along with the bytes of the actual files into one custom-defined file. You guys were very helpful, thank you!
Historically, Windows had a number of technologies to support solutions like this. These were often called Compound Files or Structured storage. However, I don't think the newer Office documents use these technologies. I think the Office file formats are similar to ZIP files with a different extensions. If you change a file with .docx extension to .zip and open it with your favorite compression tool, you'll see a bunch of folders and XML files.
Here are some links to descriptions of different file formats that create "files within files"
Zip file format
Compound File Binary Format (CFBF)
Structured Storage
Compound Document File Format
Office Open XML I: Exploring the Office Open XML Formats
At least on POSIX systems (e.g. Linux), a file is only a stream (i.e. a sequence) of bytes. And you can only grow (or shrink, i.e. truncate) it at the end - there is no way to insert bytes in the middle (without copying the rest).
You need some conventions, and some additional software, to handle it otherwise.
You might be interested in Sqlite, which gives you a library to handle some (e.g.) *.sqlite file as an SQL database
You could also use GDBM - a library giving you some indexed file abstraction.
libtar is a library to manipulate tar archives. See also tardy, a tar file postprocessor.

Find evey open MS Access instance/file

I've had an ongoing neglected question on Expert's Exchange that I would love to finally have answered. Here's the link:
My Expert's Exchange question
My objective is to return a list of every Access file that the user has open at any one time. The site includes a complete set of code to retrieve all open Excel and Word files as an array of those application objects. I've tried everything I know to solve this problem and am poised to pay Microsoft Tech Support to help me answer this question, if no one on the forums is forthcoming with an answer.
The solutions you link for Excel and Word function by looking for instances of those programs running, and using their known COM interface to find the files they have open.
With Access, other things can open the files as well. For example, a C# program or SQL Server import wizard could also have the files open.
A general solution would be rather tricky. However, if you can be sure that the files have the usual extensions, you could enumerate all files that are open in the system and return a list of those that have an appropriate file extension.
To enumerate all open files in the system, see the EnumerateOpenedFiles() method in this article
http://www.codeproject.com/KB/shell/OpenedFileFinder.aspx?fid=422864&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26&select=2277170
Note that you don't need all of the code there, as it presents a shell extension that calls EnumerateOpenedFiles() as part of it's operation. You only need that one method, modified to return only files matching the desired file extensions.

Implement a self extracting archive?

I know i can use 7z or winrar but i want to learn this for myself.
How would i implement a self extracting archive? I can use C# or C++ but let me run down the problem.
When i open the exe i need some kind of GUI asking where to extract the files. Once the user says ok I should obviously extract them. I implemented a simple example in C# winforms already BUT my problem is HOW do i get the filenames and binary of the files into an exe?
One upon a time i ask Is it safe to add extra data to end of exe? and the answer suggested if i just add data to the end of the exe it may be picked up by a virus scanner. Now its pretty easy to write the length of the archive as the last 4bytes and just append the data to my generic exe and i do believe my process can read my own exe so this could work. But it feels hacky and i rather not have people accuse me of writing virus just because i am using this technique. Whats the proper way to implement this?
Note: I checked the self-extracting tag and many of the question is how to manipulate self extracting and not how to implement. Except this one which is asking something else Self-extracting self-checking executable
-edit- I made two self extracting with 7z and compared them. It looks like... well it IS the 7z.sfx file but with a regular 7z archive appended. So... there is nothing wrong with doing this? Is there a better way? I'm targeting windows and can use the C# compiler to help but i don't know how much extra work or how difficult it may be programmatically and maybe adding data to end of exe isnt bad?
It is possible. I used the following technique once, when we needed to distribute updates for the application, but the computers were configured so that the end user had no permissions to change application files. The update was supposed to log on to administrator account and update required files (so we came across identical problem: how to distribute many files as a single executable).
The solution were file resources in C#. All you need to do is:
Create a resource file in your C# project (file ending with .resx).
Add new resource of type "file". You can easily add existing files as byte[] resources.
In program you can simply extract resource as file:
System.IO.FileStream file = new System.IO.FileStream("C:\\PathToFile",
System.IO.FileMode.OpenOrCreate);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(file);
writer.Write(UpdateApplication.Data.DataValue, 0, UpdateApplication.Data.DataValue.Length);
(Here UpdateApplication.Data denotes binary resource).
Our solution lacked compression, but I believe this is easily achieved with libraries such as C#ZipLib.
I hope this solution is virus-scanner-safe, as this method creates complete, valid executable file.

CGZIPLibrary.dll not compressing files

HI, I am using CGZipLibrary.dll in my code for zipping the files. A .zip file is being created but the file is not getting compressed. The original file and the .zip file are of same size.
Please provide some suggestions. Thanks in advance.
CGZipLibrary.dll... that's a rather old library if my memory is serving me right, I remember using it (or some other library with a similary name) in some old VB6 projects, and I had to update it because it had some problems when compressing folder structures. I may have the updated library lying somewhere around.
For .Net there are better alternatives like SharpZipLib and DotNetZip. I see the question is tagged with VB6 as well... if you need to use the library from VB6, from what I know, DotNetZip is marked as visible for COM, so you should be able to use it as well, although haven't tried it myself.

How to unrar/unzip with Objective-C, including single file retrieval

I have a need to handle various rar/zip files, in Objective-C. Ideally I'd like to be as flexible as possible in terms of rar/zip versions. I'd also like to be able to only extract certain files from the rar/zip files, after pulling out a list of the file contents.
If that wasn't enough, I'd like to be able to access and modify the zip comment.
Is this easily possible in objective-c? I've searched around a lot and found a lot of half-finished libraries that don't do everything I want, or only support rar up to version 2, or don't support extracting single files.
I know I could just use the command line unzip tool that ships with MacOS Panther and up, but this seems inelegant and doesn't help me with rar files, as no unrar application ships with MacOS by default.
Can anyone point me at a decent library that does one or the other of these two types of files, or a recommended best approach for dealing with this problem? I know that one option is to wrap the unrar source, and also wrap the zlib source, but this to me is a daunting task. If there's no other option I'll do it - any advice or guidance on this would be gratefully received.
Thanks!
Yes, doing that it's easy in objective C. For zip files just use ZLIB (it's already included in Mac OS X.
RAR is not that simple though. Look for a C library (not an Objective-C library). There will be way more C libraries for RAR handling than Objective-C ones. And you can use all C libraries you want within an Objective-C program.