# Make a zip file, from string

I am downloading a zip file from the internet and I get it as a plain text string. I now want to save this to the disk, but how should I convert this text string to a file buffer? What is needed to be done so that this string can be used in a filesystem write function?

EDIT:

The problem when I write the data directly to the disk is that the zip file becomes corrupted.

The size of the downloaded file is 34712 bytes, however when I save it directly to the disk it get the size of 64760 bytes.

The first 5 lines of the files:

The new created file as binary:
504b 0304 1400 0200 0800 47fd 3a3d 3efd
fd57 fd5b 0000 006a 0000 0c00 0000 6963
6f6e 7365 7874 2e65 7865 fdfd 7758 fd4b
1738 fdfd fdfd 2424 fa63 fdfd 4140 fd45
5a30 4840 6a28 2140 0811 1240 050c fd05

The new created file as utf8:
504b 0304 1400 0200 0800 47ef bfbd 3a3d
3eef bfbd efbf bd57 efbf bd5b 0000 006a
0000 0c00 0000 6963 6f6e 7365 7874 2e65
7865 efbf bdef bfbd 7758 efbf bd4b 1738
efbf bdef bfbd efbf bdef bfbd 2424 f48e

Original noncorrupted file from the internet:
504b 0304 1400 0200 0800 4799 3a3d 3eae
b857 865b 0000 006a 0000 0c00 0000 6963
6f6e 7365 7874 2e65 7865 edfd 7758 934b
1738 8abe e981 2424 f48e a1a3 b4d0 4140
e945 5a30 4840 6a28 2140 0811 1240 050c

• What kind of text string? If it's the binary data attempting to be displayed as text, you'd get some very weird characters. Most likely, it's Base64, which you'll have to decode. But the encoding depends entirely on the source. – Bob Mar 11 '14 at 12:41

If you insist to download stream just redirect what you are getting to the file, so:

*nix:

output_of_download_command > /path/to/file_name.zip

Windows:

output_of_download_command > c:\path\to\file_name.zip

Mind you, you might have some extra information before and/after after actual string! Without knowing exactly what you are doing it's impossible to give specific command but you can redirect all errors to different place: