binary-data

Why doesn't this program read (or write?) correctly from a .bin file? (C++)

I created this program: #include <iostream> #include <fstream> using namespace std; int main () { fstream file; file.open("test.bin", ios::in | ios::out | ios::binary); if(!file.is_open()) { return -1; } int n = 5; int x; file.write(reinterpret_cast<char*>(&n), sizeof(n)); file.read(reinterpret_cast<char*>(&x), ...

How to store the integer value "0" in a .bin file? (C++)

EDIT: Apparently, the problem is in the read function: I checked the data in a hex editer 02 00 00 00 01 00 00 00 00 00 00 00 So the zero is being stored as zero, just not read as zero. Because when I use my normal store-in-bin file function: int a = 0; file.write(reinterpret_cast<char*>(&a), sizeof(a)); It stores 0 as the char ve...

Rails: Saving the contents of a binary field to a file

I have a model with a binary field that contains a file. I'd like to save this file to disk as part of a process I need to do. For some reason, I can't find anything on how to do this. The model contains a filename field and a file_contents field. I'd like to do something like this: model = SomeModel.find :first model.file_contents.sav...

What is the most efficient binary to text encoding?

The closest contenders that I could find so far are yEnc (2%) and ASCII85 (25% overhead). There seem to be some issues around yEnc mainly around the fact that it uses an 8-bit character set. Which leads to another thought: is there a binary to text encoding based on the UTF-8 character set? ...

Reverse engineering a statistics data file from my insulin pump controller

This may or may not be a grey area subject, though my intentions are certainly not, so my intention is not to stir up an ethical debate on the topic of reverse engineering. I'm a type 1 diabetic currently undergoing pump therapy. I'm an OmniPod user, it's a disposable pod that adheres to my body and dispenses insulin for 3 days. It'...

What language is to binary, as Perl is to text?

I am looking for a scripting (or higher level programming) language (or e.g. modules for Python or similar languages) for effortlessly analyzing and manipulating binary data in files (e.g. core dumps), much like Perl allows manipulating text files very smoothly. Things I want to do include presenting arbitrary chunks of the data in vari...

.NET Stream Decoders behavior

Hello, I've got a process which attempts to decode different encodings of strings from a binary stream. I get some behavior which does not quite add up in my mind when I step through it. Specifically, what I do is: obtain the maximum number of bytes which would be used to encode a character in the given encoding grab the amount of b...

Writing integer values into binary file

Hi Lets say I have an array numbers that contains the following values: int numbers = [12, 511, 337, 254]; Now, I would like to scale those numbers into single byte values and store them in a char array char numbersscaled; for(i=0; i<4; i++) { numbersscaled[i] = numbers[i]/2; } Finally, I would like to write those valu...

Set binary data using setblob in mysql connector/c++ causes crash

I tried to use setBlob() as follows: class DataBuf : public streambuf { public: DataBuf(char * d, size_t s) { setg(d, d, d + s); } }; char b[20]; DataBuf buffer((char*)b, 20); istream stream( PreparedStatement* s = con->PrepareStatement("insert into mytable (mybin) values (?)"); s->setBlob(1, int rows = s->executeUpdate...

ASP.NET Webservice corrupts uploaded file

I have a webservice through which I can upload documents to our ASP.NET web site. The problem is when I upload PDF & word documents, they get corrupted when I try to open them. Text documents always upload fine. What is even strange is that on my development machine, these files upload fine but when I try to upload to our demo site, the...

determine if blob is an image without loading entire field?

is there a way to read only a few bytes out of a BLOB type field in a database (for this question it doesn't matter the DB brand) and determine if the binary content is an image (assume it is one of: JPG, GIF, PNG)? I have a webapp that stores files in the database, and if it is an image, I want to show a thumbnail, otherwise I want to ...

Read binary C float in Actionscript 3?

I have binary C/C++ data types (e.g. in memory version of a C float) which I need to read into Actionscript 3 and would prefer not to code this from scratch. Anyone know of any libraries, sample code, pseudo code to help with this? For example: C/C++ app: float f = 1.1; SaveFloatToFile(f, 'myfile.bin'); Actionscript 3 app: var ba:...

Returning binary content from a JPF action with Weblogic Portal 10.2

Hi, One of the actions of my JPF controller builds up a PDF file and I would like to return this file to the user so that he can download it. Is it possible to do that or am I forced to write the file somewhere and have my action forward a link to this file? Note that I would like to avoid that as much as possible for security reasons a...

Serializing a object with an image to be saved to SQL database

I have the following object: [Serializable] public class ExampleImage { public int ID { get; set; } public string Filename { get; set; } public byte[] Content { get; set; } } I store this in a List<ExampleImage> which I then pass to the following function to serialize it to a string: static string SerializeObjectToXmlStri...

efficient and flexible binary data parsing

I have an external device that spits out UDP packets of binary data and software running on an embedded system that needs to read this data stream, parse it and do somethign useful. The binary data gets logged to a file as well. I would like to write a parser that can easily take the input directly from either the UDP stream, or a file...

custom data iostream

I have a data structure defined as struct myDataStruct { int32_t header; int16_t data[8]; } and I want to take a character stream and turn it into a myData stream. What stream class should I extend? I would like to create a custom stream class so that I can do things like myDataStruct myData; myDataStruct myDataArray[10]; my...

Reading/writing binary structures: how to simplify this code?

Hi folks, I'm writing a network app, which sends and receives a lot of different kinds of binary packets, and I'm trying to make adding new kinds of packets to my app as easy as possible. For now, I created a Packet class, and I create subclasses of it for each different kind of packet. However, it isn't as clean as it seems; I've ended...

Storing XML document in pre-parsed binary format

My application need to store large amounts of XML-like hierarchical information with the following requirements: Fast to read Minimal memory consumption Typed data instead of merely text Any suggestions for a binary format that fulfills these goals? ...

Synchronizing Large Unversioned Files Within Subversion Checkout

We've been working with a Subversion repository for some time now for a research lab and have repeatedly been presented with a common issue: We want to version all of the code, and small bits of permanent data, but we also have large binary blobs that live within ignored directories in user checkouts and we'd like to make it easy for th...

Lamp / Cakephp: Streaming an image : Binary 0x00 replaced by 0x20

I'm trying to create a script that pulls an image out of the database and displays it to the user, called by <img src="viewImage/someImageName"> But the problem I'm having is when the image is displayed all of the Nulls (0x00) are replaced by 0x20 and I have no idea why. The data in the database shows it being nulls but somewhere along ...