I want to make a zip file in JavaScript with "store" level compression, i.e. no compression, without having to download a whole library like JSzip because most of the functionality isn't needed. Is there a good way to do that?
The zip file format is relatively straightforward. You can implement your own zip file creation routines that only produce stored entries. You can find the zip file format documented here.
My answer is generate the zip file on the server and let users download it.
Related
I know that JavaScript is not allowed by browsers to do much directly with the computer, and that is not my question. My question is: How to, with JavaScript, create a file on the web and then ask, perhaps with a popup window, to download the folder and any files within. This folder would need to allow access for JavaScript to place files within, like image files. This folder might originally be just another JavaScript value (like an object) or a URL.
I have done research, but much of what I found was asking whether JavaScript could create a folder directly to the computer, while my question is asking about creating the folder, and then asking to download it. There must be some way, because when in Google Drive, drive has a way to place multiple files in a .zip folder for download, and this works not just with Chrome but with Firefox and Internet Explorer. Some sites like http://stuk.github.io/jszip/ provide their own way to create .zip files, but I would prefer not to use a JavaScript library, if possible.
This would be useful for generating multiple image files, but only asking the user once for downloading them, instead of for each file.
I would prefer to create the zips client-side.
So this is an interesting question and I shall do my best to answer it. The simple solution is to not do this at all. Use javascript to asynchronously request the server to create the required .zip and then give the user a link/prompt to download. But I digress, you want it all in-house!
JSzip Option
You'll not be able to write a solid library that can .zip files client-side. JSzip is the best option out there, and it's not as solid as it could be. If you have the time you could go through the source and make improvements where required.
Cheeky Option
Your best option - baring the actual best one (server side) which you have discounted - is explained here. That is - create an iframe for each file.
Unfortunately you'll not find any better than those options if you're insisting on client-side work. Browsers weren't made to be zipping files.
I have n Javascript float arrays.
My goal is to generate and download a Zip file, using JS only, containing n CSV files, one per array.
I am aware of Javascript librairies like JSZip: http://stuk.github.io/jszip/ for generating zip files.
I also know how to generate and download a file on the fly using Blob and/or a library like FileSaver.js
However, I cannot figure out how to achieve the whole thing, client-side only.
Can anybody help me ?
How do I parse zip file string. I looked for hours I couldn't find an easy to do it. All the examples I found didn't make much sense.
I use zipjs to handle zip files. A simple library that can handle reading and writing zip files.
BE MORE CLEAR NEXT TIME. I think this answer is what you need to hear.
A zip file can not be parsed with simple JavaScript. There is simply no native function that can ope ZIP files. There are certain libraries out there, but personally i have not found one that worked properly, and most use some kind of flash plugin to make it "work".
If you really want a zip file to be presented in Javascript, you will have to build its function with PHP. PHP can write to zip files, and read them: PHP ZIP. If you want to read the contents of a zip file, you would have to upload the file to the server (can be done with JS), then make the PHP return a JSON object with all the file_info of all the files inside the ZIP. And last but not least, JS should be able to acces another PHP page that retrieves a particular file, which can be done by reading the file and setting a mimetype before outputting its contents.
I have an array of files and I want to create a zip file out of this array.
Is there a way to create zip files using jQuery?
You can use the JSZip library mentioned by several people to create the zip. However, forcing a download from javascript and having it use a custom filename is a different matter.
HTML5 introduces a download attribute on <a>s. You could use it like this:
download
Which would force the download as "something.zip" in browsers supporting the download attribute. However, besides this, there is no way to do it from JavaScript.
In my new Ruby on rails application I want to find the users country code.
So I am using MaxMind GeoIp. when I downloaded the gzip file after gunzip it gives me a GeoIP.dat file and I am stuck here. Can any one help.
If their is a program to open it or some procedure to use it.
Or if any one can suggest me the other way.
As #Kyle pointed out, you can download "human-readable" CSV files instead of binary DAT files. MaxMind's "GeoLite" downloads are here.
The CSV file format is described here.
But note (from the link above):
Due to the large size of geolocation databases, we generally recommend using our binary format with one of our APIs, since they are highly optimized for speed and disk space. On the other hand, if you have a requirement to import the data into a SQL database, the CSV format is recommended.
The APIs are listed here. There is no Javascript API listed, but there are a couple of options for Ruby.
So to answer your question directly: You would not "open" the dat file directly as you would a spreadsheet document. Instead you would write your own program that uses their API to read the dat file, and perform whatever tasks or queries you design it to do. Check out their API documentation for details of how you might get started with that.
.dat is just a file extension. The contents could be anything. Text. Binary data etc...
There is no way anyone could reliably tell you how to open the file.
I would attempt to view the contents of the file from the command line:
less file_name.dat
You can open the file and read line by line in ruby like this:
IO.readlines('file_name.dat').each do |line|
# do something with the line
end
Edit: I think I found the file you're refering to. Why not go here and download a csv version? The .dat version is not in plain text.