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), ...
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...
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...
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?
...
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'...
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...
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...
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...
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...
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...
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 ...
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:...
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...
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...
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...
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...
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...
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?
...
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...
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 ...