I'm using zlib to compress a stream of txt to a gz gzip file, and it's working well. However, it seems to name the file inside the gzip, exactly the same as my gz name.
I'm wondering is there any way to change the naming of the file that's been compressed?
I would rather it name like the following:
/myfile.gz/myfile
Where myfile is the document that's inside of the compressed gzip file, and myfile.gz is the gzipped file itself.
Is there any way to control these namings?
I think what you're saying is that when you decompress whatever.gz, you get a file named whatever in the current directory. That is the default behavior of the gzip utility, and it is not affected by how the gzip file is made. The contents of the gzip file cannot direct the decompressed data to some other directory. (If it could, that would be a security issue.)
It is possible to store a file name in the gzip header, in which case gzip -N whatever.gz will decompress to the name in the header as opposed to whatever. However it will be a file in the current directory using just the base name in the header. Any path information in the file name in the gzip header is ignored.
Related
I am trying to use the ftp method to download a csv.gz. I would also like to unzip it with the zip access function. Is there a way of combining the two in one FILENAME STATEMENT.
FILENAME in ZIP "1763.csv.gz" GZIP LRECL=80 ;
Right now I have a local copy of the file but would instead like to pull it down through FTP.
As far as I know, this isn't doable in a single filename - you have to have two, one for the FTP and one for the Zip.
However, you can stream the file to a (temporary) local file, and then access that same file with FILENAME ZIP. One paper that talks about this method is this from SGF 2019; there are several other similar that have the same basic approach:
filename ftp to your ftp file
Data step to read in from filename ftp and write out using recfm=n to a (temporary) file
filename zip to read in the file created in step 2.
I have written a zip class that uses functions and code from miniz to: Open an archive, Close an archive, Open a file in the archive, Close a file in the archive, and write to the currently open file in the archive.
Currently opening a file in an archive overwrites it if it already exists. I would like to know if it is possible to APPEND to a file within a zip archive that has already been closed?
I want to say that it is possible but I would have to edit all offsets in each of the other file's internal states and within the central directory. If it is possible - is this the right path to look in to?
Note:
I deal with large files so decompressing and compressing again is not ideal and neither is doing any copying of files. I would just like to "open" a file in the zip archive to continue writing compressed data to it.
I would just like to "open" a file in the zip archive to continue writing compressed data to it.
Compressed files aren't working like a file system or folder, where you could change individual files. They keep e.g. check sums, that need to apply for the whole archive.
So no, you can't do such inplace, but have to unpack the compressed file, apply your changes and compress everything again.
I have approximately 130,000 gz files, each containing one file which needs to be renamed with a .xml extension in order to be viewed properly. For example, on gz file might be named 100.san.form.gz and contain the file 100.san.form, which needs to be renamed to 100.san.form.xml to be viewed appropriately.
I am trying to write a script to unzip all of these files and then rename them appropriately, and read them into my program to parse.
i working on ClamAV antivirus database.
ZMD one of clamav database file who store information about malice's zip file.
i need to get this information from zip file but if possible not use any component
is encryption.
normal size
compressed size
CRC32
compression method
please help me.
You can use unzip -l to list the contents or you can write your own zip format decoder to extract the information from the headers. The format is documented in the .ZIP File Format Specification.
I am implementing a HTTP/1.0 server that processes GET or HEAD request.
I've finished Date, Last-Modified, and Content-Length, but I don't know how to get the Content-Type of a file.
It has to return directory for directory(which I can do using stat() function), and for a regular file, text/html for text or html file, and image/gif for image or gif file.
Should this be hard-coded, using the name of the file?
I wonder if there is any function to get this Content-Type.
You could either look at the file extension (which is what most web servers do -- see e.g. the /etc/mime.types file; or you could use libmagic to automatically determine the content type by looking at the first few bytes of the file.
It depends how sophisticated you want to be.
If the files in question are all properly named and there are only several types to handle, having a switch based file suffix is sufficient. Going to the extreme case, making the right decision no matter what the file is would probably require either duplicating the functionality of Unix file command or running it on file in question (and then translating the output to the proper Content-Type).