erl_tar can't extract files made with make_tar - erlang

I'm putting a release file together, which seems to work fine
1> systools:make_tar("rel/project-1.0").
ok
at that point, I get the expected file at rel/project-1.0.tar.gz, however, trying to extract it errors for some reason
2> erl_tar:extract("rel/project-1.0.tar.gz").
{error,bad_header}
Trying to extract the same file with tar from shell, or with the equivalent os:cmd/1 call, works fine. What's going wrong here?

The archive is gzip compressed (notice the .gz extension). You will need to use extract/2 and provide the compressed option:
erl_tar:extract("rel/project-1.0.tar.gz", [compressed]);

Related

Lua io.write() not working

I am using a luvit Lua environment to run my lua code through my control panel. I am looking to write to a .txt file, but with the simple code that i am running, its not working.
The reason I wish to write to a .txt file is to log notices from my Discord Bot I am working on in the Discordia library.
I have a folder called MezzaBOT. In this file i have a write.lua file and also a log.txt file. I have this simple code in my write.lua file:
io.output('log.txt')
io.write('hello\n')
io.close()
I then run in my command promt with Luvit environment:
>luvit Desktop\mezzabot\write.lua
I don't get any errors but the log.txt file continues to stay empty. Am I missing a line in my code, or do i need to access log.txt differently?
edit: my new code is the following
file = io.open('log.txt')
file:write('hello', '\n')
file:close()
and it is not making a new line for each time with \n
edit B:
Ok, i found my problem, its creating a log.txt in my C:\Users\PC.
One other problem is when writing, its not making a new line with the \n. Can someone please help me?
Lua, by default, opens files in read mode. You need to explicitly open a file in write mode if you want to write to it (see manual)
file = io.open('log.txt', 'w')
file:write('hello', '\n')
file:close()
Should work :)

Why doesn't grep work on some file, but works on another (same content)

I wrote this grep command:
grep -- "^[0-9a-zA-Z\.-]\+$" file.txt
To get all lines containing only numbers, letters and dashes (legal domains).
This is the result of diff on both files
1,3c1,3
< test.xcom
< hi-th6ere.co.k
< 54
---
> test.xcom
> hi-th6ere.co.k
> 54
I wrote a file with some domains to test and it works great!
But, when I download a file (with the same content!) from the web, and then run this command, grep doesn't return anything.
I've tried to set full permissions on this file, but it still doesn't work.
Any ideas?
Thanks,
What makes you think the file content as the same as the one you've tested?
You can run 'diff filename1 filename2' to see if there are any differences between the two files.
It could be the the file you're downloading is in unicode format, so in a web browser it looks to be have the same content as the file you've tested, but the binary content of the file itself is different.

Produce a download file from CGI in Lua

I am writing a simple CGI program in lua. What I want to achieve is produce a response from CGI which enables a file to be downloaded from the browser. But I just can't print the data. I have no idea what's going on here. Here is the code below:
print("Content-Type: text/html; charset=UTF-8")
print("Content-Length:" .. sys.getenv("CONTENT_LENGTH"))
print("Content-Disposition:",'attachment;filename="backup.tar.gz"\n')
print("Content-Type:application/x-tar-gz\n\n")
file=io.popen("some command")
output = file:read('*a')
print(output)
--file:close()
The problem is I just can't print the output whose content is binary. I can see the type of output is string.
What is the problem? Please give some hints about it. Thank you.
ADD : I have no idea about this and Where is the issue. Let me put more info about the command I want run. But I don't think that matters.
Actually, I work in openwrt, the web server uhttpd. (No LuCI here)
The command is:sysupgrade -b - 2>/dev/null. This command is used to backup the config file. I want to write a CGI to download the backup file from the web.
But I can not print the output to the server. Even in the terminal(in lua IDE) I cannot print out the output except one or two messy code. But I can write the output to a file in terminal. Maybe it has some relationship with the content of out.
When I print the content line by line, it prints some, but not all of it. After I download the file. I can't open it.
print("Content-Disposition:",'attachment;filename="backup.tar.gz"\n')
print("Content-Type:application/x-tar-gz\n\n")
I think you have way too many new lines. First of all, you can newline in Content-Disposition and this is in addition to the newline that print adds, which ends the headers and makes Content-Type a part of the payload (which breaks the content). You also have two newlines in Content-Type where you only need one (as one is added by the print command).
I think something like this should work:
local file = io.popen("some command")
local output = file:read('*a')
file:close()
print("Content-Type: text/html; charset=UTF-8")
print("Content-Length: " .. #output)
print("Content-Disposition: " .. 'attachment;filename="backup.tar.gz"')
print("Content-Type: application/x-tar-gz\r\n")
print(output)

OpenCV header error (YAML)

Ok so I feel that I have finally successfully used the OpenCV libraries in my app, except for one thing...
My .yml files get generated correctly except the '%YAML:1.0' header at the top turns out like this '01%YAML:1.0'. The '01' infront of the header is causing this error (I think):
OpenCV Error: Parsing error (/var/mobile/Applications/53C6CBA3-15B7-436A-892B-2ECFA75B72CD/Library/DownloadedDescriptors/descriptors.yml(1): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /Users/Dash/Documents/SmartServices/AirLink/ProjectGhost/FairfaxNewsDemo/opencv-2.3.1/OpenCV-2.3.1/modules/core/src/persistence.cpp, line 2163
Anyone know how to solve this issue?
Ok after looking into it a bit further I dont think it's the headers problem. My file always gets generated with '01' at the start.
Hmm...this is embarrassing. But it turns out that I had a 'print' statement lingering in the php file that helps generate my .yaml file, causing 0 and 1 to be added to the beginning of the document.
This meant that my file didn't start with '%YAML:1.0' as expected but '01%YAML:1.0'

unzOpen returns null while unzipping tz file in iphone

I am using ZipArchive to unzip tz files in my iphone App. It works fine when I have a sample tz file which contains text files inside it. However, my main usage is to try to unzip a tz file containing Json files. When I try to do that nothing happens as I am not able to access my file and I am not coming to a conclusion regarding to what am I doing wrong here?
Only thing I have come to know is this
_unzFile = unzOpen( (const char*)[zipFile UTF8String] );
This line of code returns me a proper _unzFile and works fine with the sample .tz file which contains .txt files. However, when I try it with my .tz file which contains a json file in it, _unzFile contains nothing (i.e 0x0). Is there any problem with UTF8String function? Or else what am I doing wrong?
Please help! Thanks.
Generally it is the problem of the zip file to be uncompressed. In my condition, I used some other files, compress them manually and decompress them with the code, the unzOpen works properly. I used ASIHTTPRequest, downloaded and renamed the zip file, I suppose it could be made wrong here. Therefore, check the zip file itself please.

Resources