I see an example where the data was in text inside an array, i seen another where someone loads the model through ajax with json.
Is there a way to load the files via binary? i dont feel like loading a 1mb model via 4mb json
It is certainly possible to load binary files.
http://blog.nihilogic.dk/2008/05/reading-exif-data-with-javascript.html
But the problem is after that. That you need to know what format it is in. And extract everything from there.
You can use jQuery Binary Ajax, or for new browsers, ArrayBuffer
If file is compressed with gzip then json size is almoast same as binary file size.
Anyway you can use binary loader from three.js if you really need it.
Related
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 application that requires I convert a PCX graphic to binary. There is very little info on the internet on how to do this. I can accomplish this with canvas.toDataURL using JS but only for PNG and JPEG graphic files. This is not for a SQL database as I think you can do it there. Any help would be appreciated, even if it involves using an app to get me there.
I have no idea what you mean by your question, but I presume that if you can do whatever it is that you want with a JPEG file but can't do that with a PCX file, it would help if you could convert your PCX to a JPEG.
So I would suggest you use "convert" from ImageMagick (here)
convert image.pcx image.jpg
Here is a text file:
This is the first line
You can read me, con't you?
Yes, it's because I am text
Here is a binary file:
<FF><D8><FF><E0>^#^PJFIF^#^A^A^A^#^A^#^A^#^#<FF><DB>^#C^#^C^B^B^B^B^B^C^B^B^B^C^C^C^C^D
^L^R^S^R^P^S^O^P^P^P<FF><DB>^#C^A^C^C^C^D^C^D^H^D^D^H^P^K ^K^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P^P<FF><C0>^#^Q^H^A<90>^#<C8>^C^A"^#^B^Q^A^C^Q^A<FF><C4>^#^]^#^#^#^G^A^A^A^#^#^#^#^#^#^#^#^#^#^#^B^C
^D^E^F^G^H^A <FF><C4>^#8^P^#^A^C^C^C^B^E^B^D^F^C^#^B^C^#^#^A^B^C^Q^#^D!^E^R1^FA^G^S"Qaq<81>^T2<91><A1>^H^U#B<B1><D1>R<C1><E1>^V<F0>3br<FF><C4>^#^Z^A^#^B^C^A^A^#^#^#^#^#^#^#^#^#^#^#^B^C^A^D^E^#^F<FF><C4>^#/^Q^#^B^B^A^D^A^C^
Assuming I have some images, css and html concatenated in one file. Is it possible to use JS to display the html with images and css properly by ripping up the concatenated binary file somehow?
There are some ways to pack everything into a single file. But all of them are not crossbrowser. Everything depends on your goals.
Take a look at these formats:
MHTML http://en.wikipedia.org/wiki/MHTML
Webarchive http://en.wikipedia.org/wiki/Webarchive
Mozilla Archive Format http://en.wikipedia.org/wiki/Mozilla_Archive_Format
All of them are browser specific and even requires some extensions to be installed.
The easiest and the most supported way is to put all css and js files right into your html file. And use data:uri format to include your images into html.
Theoretically it is even possible to write a binary file reader in javascript.
Is there any way to determine if a JPEG file is corrupt after reading it via the FileReader API in JavaScript?
I'm thinking about something like what "libjpeg" does. It provides warning messages if something is wrong with the JPEG file.
There are some libraries which do JPEG decoding in Pure JavaScript.
E.g. https://github.com/notmasteryet/jpgjs (there are others)
You can simply decode the FileReader fed data in your JavaScript code and see if the output is sane.
Depending of the degree of corruption, what cases you want to trap, it should be possible on client-side.
I'm working on a image editor/uploader based around Pixastic where I grab image data out of an <input> tag, put it into a canvas, and after manipulating it, encode the data in base 64 and post it to my app with javascript, where it will be saved as a new image file. If it were a standard file upload, I would give the file a new (safe) name, test to make sure it was really an image file and copy it to strip any potentially malicious/personal EXIF data before making it available to users.
My question is - do those security measures make sense in the canvas situation, or are they pointless? Additionally, are there any security issues with my approach that I'm overlooking?
Fyi: the serverside decoding/etc will be done with php.
Thanks.
Some of what you have asked (Not sure if all) are discussed by Shiflett Here
Check it and comment what you think of it!