I have identified a random series of bytes inserted into any blob field when the database is manipulated via Adobe AIR. (from my results it appear to always start with bytes[12, ...] but I'm not sure of that)
I think it's a sizeinfo of the bytes, let me explain how I came to this conclusion.
First my context : I manipulate sqlite databases through Adobe AIR (client-side) and System.data.sqlite (C# server-side)
With System.data.sqlite if I read a Sqlite db filled with BLOB by Adobe AIR I have to get ride of those bytes appended in the beginning by AIR and then I have the binary data all well shaped. PERFECT!
With Adobe AIR if I tried to read a sqlite db filled with BLOB by System.data.Sqlite the data are corrupted I get an error! Obviously because I don't have the missing bytes researched by AIR.
Of course I tried to add those bytes by just copying a series of 3 bytes that I removed in my first case but then it returned the data partially and in the cases of images the last rows of pixels go all gray and in some images I have more or less grays lines. Because the data were corresponding to a series of images of the same ~4k size and I added 3 bytes from one of them and I had this result.
And Air will also sometimes throw this error :
Error: Error #2030: End of file was encountered.
So obviously those bytes give an info on the size but I don't really get how it does!?!
I tried to add a bytearray with 4k length it tends to add 3 bytes but I tried to add 4M and it goes up to 5 bytes.
I found this Question How do you convert 3 bytes into a 24 bit number in C#? and I thought that could be how the size info is stored.
But I still don't get it...
Thanks to FluorineFX (AMF for .NET) opensource project here is the answer.
Because in my Adobe AIR project I have to pass my air.ByteArray object as a parameter to store everything in the sqlite Blob field; AIR will serialize everything into AMF, a compact binary actionscript message format.
Page 11 Secion 3.14 ByteArray type
http://opensource.adobe.com/wiki/download/attachments/1114283/amf3_spec_05_05_08.pdf
The doc stipulate :
But thats not all, I searched for an AMF .NET opensource project and founded FluorineFX. Looking into the code I identified that every AMF binaries is prefixed with a byte TypeCode which is 12 for a ByteArray:
Further search and again I found in the FluorineFX sources AMFReader.ReadAMF3ByteArray() and AMFWriter.WriteByteArray()
Which help me to quickly build what I need :
I hope that will help someone else.
Thanks a lot, that helped me solve the problem. Here is how to do it with Java code:
Add org.granite granite-core dependency to your project
Init GDS with boilerplate code
In my example, i read an image file that i will insert into a BLOB:
Works like a charm, thanks for the hint :)
Fabien