Ruby Zlib: What is the purpose of orig_name=? - zlib

My code is like this:
gz = Zlib::GzipWriter.open('test.zip')
gz.orig_name = "test.csv"
gz.write("testing writing to zipped file")
gz.close
What I am trying to do:
When using zip extractor application, test.zip will be unzipped to test.csv
I used orig_name method thinking that when I will try to extract the zip with other zip extractor like archive utility, the resulting file would be 'test.csv'. But the file is still 'test'.

If by "other zip extractor" you mean the gzip utility, you'd need to use the -N option of gzip to use the name stored in the gzip header. Otherwise it will just use the compressed file name with the .gz removed.

Related

How to zip multiple datasets from different folders in one zip file SAS

I have a macro that creates a zip file to archive all datasets from ONE folder. I would also like to also include only a few datasets from a different folder into that same zip file, if possible?
I'm using an already built out macro call 'zip(path, zip name, ziplock);' which will create a zip file from a folder. How can I add other datasets from another folder in that zip file without moving the datasets into that folder manually after.
The macro parameters are defined below:
path = file path of directory to be zipped
zip name = name of new zip file
ziplock = location of new zip file
I would like to zip an entire folder AND a few datasets from another folder
It's not possible to answer for your macro without seeing the macro, but there are ways to zip files in SAS, and here's one.
https://blogs.sas.com/content/sasdummy/2016/03/04/add-files-to-a-zip-archive-with-filename-zip/
Basically, you use a filename to the zip file:
filename zipfile "\\path\to\zipfile.zip";
Then you make a specific filename to the member inside the zipfile:
filename newfile zip "\\path\to\zipfile.zip" member="path\to\sasfile.sas7bdat";
Then you use byte-wise streaming to copy the file in. From the above post with minor edits:
data _null_;
infile data_fn recfm=n;
file newfile recfm=n;
input byte $char1. #;
put byte $char1. #;
run;
data_fn is the actual physical filename of the sas dataset you are adding.
This works fine with files from different folders, so you can easily use this for whatever you want.

Tricentis Tosca - How to open a file which is the first file in a folder, or the only file in a folder. Note - I dont know the file name

The System Under Test generates some pdf files and saves the files to a particular folder. The challenge is that the pdf file name is randomly generated and I don't know the name. I need to open the file from the folder which is the most recent one, but I can't seem to find a way to open the file.
I know part of the file name so I tried using wildcard for part of the file name, but it doesn't work
I removed all other files from the folder and kept only one file in the folder, and then used wildcard instead of the complete file name, but that doesn't work either
Is there a way that I can read names of files present in a folder? Or open a pdf file using wildcard character? Or open the first file in the folder?
You could try PowerShell scripting (please refer attached screenshots)
Use the 'TBox Start Program' module.
In the Path attribute, mention the complete path of your PowerShell exe file (Eg: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe)
In the Directory attribute, mention the folder path(Eg: C:\Users\tosca\Documents\testfolder)
Put -command in arguments with ActionMode 'Select'.
As Argument, input the PowerShell script with your wild carded file name to copy the file name (Eg:
(Get-ChildItem filename | Sort-Object CreationTime -Descending | Select-Object -First 1).Name | Clip)
Copy latest file name
Then use 'TBox Clipboard' to store the dynamic file name using ActionMode 'Verify'
Save latest file name
Then you can buffer the target file as folderpath\filename.

What mime type should I use for CSV ZIP files?

I am trying to send an email using Simple Java Mail API. The email will contain a CSV ZIP file attachment. Should I use text/csv or application/zip for the mime type of the attachment?
A zip file is a zip file, no matter what it contains.
It should be application/zip.
It is not a CSV file, if you tried to parse it as CSV it would fail. It is not text/csv.
In linux, you can find way much of the in the following file: /etc/mime.types.
See below to find out what mime is suitable for zip files.
grep zip /etc/mime.types
application/bacnet-xdd+zip xdd
application/epub+zip epub
application/gzip gz tgz
application/lpf+zip lpf
application/prs.hpub+zip hpub
application/tlsrpt+gzip
application/vnd.airzip.filesecure.azf azf
application/vnd.airzip.filesecure.azs azs
application/vnd.comicbook+zip cbz
application/vnd.d2l.coursepackage1p0+zip
application/vnd.dece.zip uvz uvvz
application/vnd.espass-espass+zip espass
application/vnd.etsi.asic-e+zip asice sce
application/vnd.etsi.asic-s+zip asics
application/vnd.exstream-empower+zip mpw
application/vnd.ficlab.flb+zip flb
application/vnd.gov.sk.e-form+zip
application/vnd.imagemeter.folder+zip imf
application/vnd.imagemeter.image+zip imi
application/vnd.iso11783-10+zip
application/vnd.laszip
application/vnd.logipipe.circuit+zip lcs lca
application/vnd.software602.filler.form-xml-zip zfo
application/vnd.stepmania.package smzip
application/zip zip
image/vnd.airzip.accelerator.azv azv
model/vnd.usdz+zip usdz
application/x-bzip2 bz2

jMimeMagic returning mime type for docx, pptx, jar files as application/zip

I read the mimetype for .docx file is application/vnd.openxmlformats-officedocument.wordprocessingml.document. But when I upload a .docx file(one that I just created, not from a zip file) and check for its mimetype in my application using
String mimeType = Magic.getMagicMatch(file1, false).getMimeType();
I get Mimetype as application/zip.
I get the same result when I try to upload a .jar file.
I mean this way, how can I check if the user is uploading a msword or a jar file to my application?
All of the .*x Office variants (.docx, .pptx, and so on) are XML-based content which is wrapped in a ZIP "container" to keep them compact, and your library is detecting the ZIP header correctly but then either not checking for, or failing to find, the additional information that would allow it to distinguish those from a ZIP file containing whatever random data someone put into it.
Similarly, the JAR file format is an extension of the ZIP file format, so if the library does not know to check for the "special type of ZIP" case, it would simply report it as a ZIP file.

Regarding changing the file extensions of all files in a folder in ubuntu 14.04

I have a folder containing number of files with extensions in .xvg format and i need to change them into .dat format. How can i do that..?
What are the commands that i need to give such that all those files extensions that are in .xvg format are converted into .dat format [without the file name getting changed,(example., abc.xvg should be converted into abc.dat),only file extension should be changed].
Try this
rename 's/.xvg$/.dat/' *.xvg
For a test run you can use this command:
rename 's/.xvg$/.dat/' *.xvg -vn
-v means "verbose" and it will output the names of the files when it renames them.
-n will do a test run where it won't rename any files, But will show you a list of files that would be renamed.

Resources