I need to archive multiple files using ruby, but I need to archive them in such way that they could be extracted without using my script (so I need popular format).
Problems with tar are max file length and problems with random file access while writing tar.
Good pure ruby library or ruby binding is highly desirable.
Built-in compression would be a good addition (so i don't need to use zlib ruby binding around archiving).
Ruby Zip is very stable, we use it to allow users to download bundles of images.
So why not just use something like this
`tar -czf myarchive.tgz myfiles/*`
from inside of your ruby script? If they have the executable to extract the files, surely they have a command line tar executable.
Related
SO...
I am writing a ruby script to initialize a production host in order to run an application (create user groups, users, SSH keys, etc.) and I am stuck on installing NPM / Node. I don't want to use a package manager to install it, but rather simply grab the .tar.xz file for the version I want (in this case, 6.9.1) and unpack it to a location I want with the binaries added to my path. Currently, we will get this from Node downloads...
I have found this SO answer that I am using to try and get my script working. It looks like Ruby does not have an out of the box way to handle ".xz" files, but my Ubuntu distribution does have a later version of tar so it can handle "tar -xJf ...". I was thinking to do something along the lines of...
require 'fileutils'
require 'open-uri'
uri = "https://nodejs.org/dist/v6.9.1/node-v6.9.1-linux-x64.tar.xz"
source = open(uri)
data = system("cat", IO.binread(source), "|", "tar", "-xJf", "-")
# put data where I want using FileUtils
...I could definitely get this working with an intermediate file and more system commands (or even just a curl call for that matter, but I am trying to not use system calls where possible). I see there are Gems that I can use such as this, but I would like to not include any dependencies. Any thoughts on achieving an elegant solution?
system is too weak. You want IO::popen for this.
IO.popen(['tar', '-xJC', target_dir, '-f', '-'], 'wb') do |io|
io.write(IO.binread(source))
end
popen will open a subprocess, and give you io connected to its stdin/stdout. No need for FileUtils, -C option tells tar where to put stuff.
Hi this question seems to be answered but answers don't resolve my problem.
I try to include lua script into executable by copying it into exe
copy -b a.exe+test.lua output.exe
but when i launch output.exe luaL_dofile() cannot find lua script.
I dont want to use any third party apps to achieve this.
Copying files seems to work because Love2D projects works and I copy files in the same way but i treats them as zip archive (for sake of file hierarchy).
You can append a Lua script to your .exe but you'll need some way to load it into your program. The main problem is how to find the Lua script at the end of the .exe. srlua appends a small signature that contains the size of the Lua script so that the program can read the script at the right offset in the .exe file. Fortunately, the Lua API provides a function to load scripts from arbitrary sources. The convenience function luaL_dofile uses that function. You can use the same technique in your own program.
I am writting expansion programs to a CAD program called 12d Model. The language I write these expansions in is simply called Macro language and it has a very limited API. So it doesn't have a way to find a file on Windows, list all files in a directory or download a file.
To overcome this I use simple ShellExecute and system calls. For example to list all files in a directory I use the system call "dir C:\ /B > C:\MyCurrentFolder\outfile.txt". One of my needs is to download and parse an XML file but the API has no download function.
Is there a system call to download a file from a URL? Is there some native way to do this? Maybe there is a Windows Application like regedit.exe or something that I can use to download a file?
If not, do you think it would be possible to do it through a batch script?
Windows does have built in FTP support using ftp.exe. So if you could find a FTP mirror of the file, or upload it to one yourself, that might work.
Yes there is a native way to do this. Use the msxsl.exe parser to download the xml file and save it to whatever location you would like. You can do this from the command prompt or from a batch file. Note the one caveat to this is you will need to use an xsl file that does not alter the xml file. The command would look something like this...
c:\msxsl.exe c:\myXML.xml c:\myXSLT.xsl > c:\myXML.xml
Note here the file located at c:\myXSLT.xsl cannot change the source file c:\myXML.xml
I'm currently trying to find a way to concatenate several files, typically all files from within a directory (recursive included) into a single stream, for further processing.
TAR looks like an obvious candidate, except that it is not at all standard in Windows, and unfortunately, all versions i could find (mostly variations of GNU TAR) are much too big (several hundreds of KB once included DLL dependencies). I need something much smaller.
Apparently, the standard COPY command could do the trick. For example the following command works:
COPY /B sourcefile1+sourcefile2 destinationfile
However, there are still 2 problems : I don't know how to write the result to stdout (for pipe), and even more importantly how to achieve the reverse operation ?
I need a small utility to do this concatenation job, either in C source code, a standard windows command, or as a distributable binary. It doesn't need to respect the TAR format (although it is not a bad thing if it does). And obviously the concatenation shall be reversible.
I suggest using 7-zip. It has portable version, can compress very good (or just copy without compression) all files recurse subdirectories and write output to single stream (stdout).
It has "-so" (write data to stdout) switch. For example,
7z x archive.gz -so > Doc.txt
decompresses archive.gz archive to output stream and then redirects that stream to Doc.txt file.
7z a -tzip -so -r src\*.cpp src\*.h > archive.zip
compresses the all *.cpp- and *.h- files in src directory and all it subdirectories to the 7-Zip standard output stream and writes that stream to archive.zip file (remove "> archive.zip" and intercept output by your program).
Why don't you use ZIP (disable compression if you want)? It's very standard, and support comes built into Windows. See Creating a ZIP file on Windows (XP/2003) in C/C++
Pure concatenation isn't reversible, because you can't know where to split it again. So you should use a directory of chunk sizes, such as exists in the ZIP and TAR formats.
Well, Shelwien's almost solved the issue.
The Tar version he proposes is "lean anough" (~120KB) and does not necessitate external DLL dependancies.
http://downloads.sourceforge.net/project/unxutils/unxutils/current/UnxUtils.zip
Unfortunately, it also has some problems of its own, such as no support for Unicode characters, interpreted escape sequence (so a directory name starting with t triggers a \t which is considered a tabulation), and a potential problem with pipe implementation under Windows XP (although on this last one it could come from the other program).
So that's a dead end.
A solution is still to be found...
[Edit] Shelwien just provided a solution by creating "shar", a tar replacement much smaller and much more efficient, without the limitations described above. This solve the issue.
How do I extract all the dependencies from a Windows file in Python? So I basically want to extract all the used exe,dll,osx,sys etc. files.
I would like to to this in Python or directly with grep.
Pefile can help you parse PE executables. You can find some usage examples on the project's page.