binaryfiles

Python - converting wide-char strings from a binary file to Python unicode strings

 ̄綄美尐妖づ 提交于 2020-02-02 02:57:05
问题 It's been a long day and I'm a bit stumped. I'm reading a binary file that contains lots of wide-char strings and I want to dump these out as Python unicode strings. (To unpack the non-string data I'm using the struct module, but I don't how to do the same with the strings.) For example, reading the word "Series": myfile = open("test.lei", "rb") myfile.seek(44) data = myfile.read(12) # data is now 'S\x00e\x00r\x00i\x00e\x00s\x00' How can I encode that raw wide-char data as a Python string?

VB - How do I read and write a binary file?

谁都会走 提交于 2020-01-31 05:29:06
问题 How do I read a raw byte array from any file... Dim bytes() as Byte ..and then write that byte array back into a new file? I need it as a byte array to do some processing in between. I'm currently using: To read Dim fInfo As New FileInfo(dataPath) Dim numBytes As Long = fInfo.Length Dim fsAs New FileStream(dataPath, FileMode.Open, FileAccess.Read) Dim br As New BinaryReader(fs) Dim bytes As Byte() = br.ReadBytes(CInt(numBytes)) br.Close() fs.Close() To write Dim fs As System.IO.FileStream fs

difference between text file and binary file

你离开我真会死。 提交于 2020-01-30 14:13:12
问题 Why should we distinguish between text file and binary files when transmitting them? Why there are some channels designed only for textual data? At the bottom level, they are all bits. 回答1: At the bottom level, they are all bits... true. However, some transmission channels have seven bits per byte, and other transmission channels have eight bits per byte. If you transmit ASCII text over a seven-bit channel, then all is fine. Binary data gets mangled. Additionally, different systems use

Store data from binary file into dynamic array of strings

随声附和 提交于 2020-01-25 03:10:33
问题 I have a binary file where I store numbers as strings in this fashion: 11 43 89 101 etc I want, by using only system commands, to read the numbers stored and store them in a string dynamic array, because i don't know how long the strings will end up being or how many. Here is the relevant code: char **positions; int all_names=0,i,j; fd=open(argv[2],O_RDWR|O_CREAT,S_IRWXU); i=0; j=0; do{ positions=(char**)malloc(sizeof(char*)); (*positions)[i]=(char*)malloc((MAX_SIZE+1)*sizeof(char)); do{ read

Sorting gigantic binary files with C#

↘锁芯ラ 提交于 2020-01-22 12:46:48
问题 I have a large file of roughly 400 GB of size. Generated daily by an external closed system. It is a binary file with the following format: byte[8]byte[4]byte[n] Where n is equal to the int32 value of byte[4]. This file has no delimiters and to read the whole file you would just repeat until EOF. With each "item" represented as byte[8]byte[4]byte[n]. The file looks like byte[8]byte[4]byte[n]byte[8]byte[4]byte[n]...EOF byte[8] is a 64-bit number representing a period of time represented by

How to search pattern in big binary files efficiently

六月ゝ 毕业季﹏ 提交于 2020-01-22 02:04:40
问题 I have several binary files, which are mostly bigger than 10GB . In this files, I want to find patterns with Python , i.e. data between the pattern 0x01 0x02 0x03 and 0xF1 0xF2 0xF3 . My problem: I know how to handle binary data or how I use search algorithms, but due to the size of the files it is very inefficient to read the file completely first. That's why I thought it would be smart to read the file blockwise and search for the pattern inside a block. My goal: I would like to have Python

Reading integers in different endianness from binary file in C++

﹥>﹥吖頭↗ 提交于 2020-01-17 02:17:06
问题 I'm reading an ESRI Shapefile, and to my dismay it uses big endian and little endian at different points (see, for instance, the table at page 4, plus the tables from page 5 to 8). So I created two functions in C++, one for each endianness. uint32_t readBig(ifstream& f) { uint32_t num; uint8_t buf[4]; f.read((char*)buf,4); num = buf[3] | buf[2]<<8 | buf[1]<<16 | buf[0]<<24; return num; } uint32_t readLittle(ifstream& f) { uint32_t num; f.read(reinterpret_cast<char *>(&num),4); //f.read((char*

masking most significant bit

拥有回忆 提交于 2020-01-16 10:38:06
问题 I wrote this function to remove the most significant bit in every byte. But this function doesn't seem to be working the way I wanted it to be. The output file size is always '0', I don't understand why nothing's been written to the output file. Is there a better and simple way to remove the most significant bit in every byte?? 回答1: In relation to shift operators, section 6.5.7 of the C standard says: If the value of the right operand is negative or is greater than or equal to the width of

masking most significant bit

筅森魡賤 提交于 2020-01-16 10:38:02
问题 I wrote this function to remove the most significant bit in every byte. But this function doesn't seem to be working the way I wanted it to be. The output file size is always '0', I don't understand why nothing's been written to the output file. Is there a better and simple way to remove the most significant bit in every byte?? 回答1: In relation to shift operators, section 6.5.7 of the C standard says: If the value of the right operand is negative or is greater than or equal to the width of

C++ Binary File I/O Operations Slow Down… How DB Handle Binary Files?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 09:06:42
问题 I am trying to make a simple file-based hash table. Here is my insert member function: private: std::fstream f; // std::ios::in | std::ios::out | std::ios::binary public: void insert(const char* this_key, long this_value) { char* that_key; long that_value; long this_hash = std::hash<std::string>{}(this_key) % M; long that_hash; // also block status long block = this_hash; long offset = block * BLOCK_SIZE; while (true) { this->f.seekg(offset); this->f.read((char*) &that_hash, sizeof(long)); if