binaryfiles

Extract zlib compressed data from binary file in python

僤鯓⒐⒋嵵緔 提交于 2019-12-18 04:18:07
问题 My company uses a legacy file format for Electromiography data, which is no longer in production. However, there is some interest in maintaining retro-compatibility, so I am studying the possibility to write a reader for that file format. By analyzing a very convoluted former source code written in Delphi, the file reader/writer uses ZLIB, and inside a HexEditor it looks like there is a file header in binary ASCII (with fields like "Player", "Analyzer" readily readable), followed by a

binary file to string

无人久伴 提交于 2019-12-18 04:16:08
问题 i'm trying to read a binary file (for example an executable) into a string, then write it back FileStream fs = new FileStream("C:\\tvin.exe", FileMode.Open); BinaryReader br = new BinaryReader(fs); byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length)); System.Text.Encoding enc = System.Text.Encoding.ASCII; string myString = enc.GetString(bin); fs.Close(); br.Close(); System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] rebin = encoding.GetBytes(myString); FileStream

Posting form-data and binary data through AWS API Gateway

白昼怎懂夜的黑 提交于 2019-12-17 18:40:17
问题 I'm trying to POST "mutlipart\form-data" to my EC2 instance through AWS API Gateway, but I couldn't find a way to this. There is a way to post data using "application/x-www-form-urlencoded" and Mapping Tamplate to convert it to JSON but still posting a binary data like an image file is missing I guess. Is there anything I'm missing ? EDIT: I have found another way: I convert the image to base64 string then POST it as with content type "application/x-www-form-urlencoded". By this way I'm

Git or Subversion for binary files

左心房为你撑大大i 提交于 2019-12-17 15:33:10
问题 We need to store binary files (mostly MS Word documents, ranging from a couple of KB to a couple of MB in size) in a version control repository with over 100 "projects". Currently we use Visual Source Safe but there are some problems, the database is crashing sometimes and the access is slow. We are considering moving to Git or Subversion and we were wondering which one would be a better option for handling binary files. 回答1: Subversion, definitely. Today (2009), TortoiseSVN provides Explorer

How to read a binary file into a vector of unsigned chars

社会主义新天地 提交于 2019-12-17 07:08:18
问题 Lately I've been asked to write a function that reads the binary file into the std::vector<BYTE> where BYTE is an unsigned char . Quite quickly I came with something like this: #include <fstream> #include <vector> typedef unsigned char BYTE; std::vector<BYTE> readFile(const char* filename) { // open the file: std::streampos fileSize; std::ifstream file(filename, std::ios::binary); // get its size: file.seekg(0, std::ios::end); fileSize = file.tellg(); file.seekg(0, std::ios::beg); // read the

How to identify the file content as ASCII or binary

老子叫甜甜 提交于 2019-12-17 05:47:07
问题 How do you identify the file content as being in ASCII or binary using C++? 回答1: If a file contains only the decimal bytes 9–13, 32–126, it's probably a pure ASCII text file. Otherwise, it's not. However, it may still be text in another encoding. If, in addition to the above bytes, the file contains only the decimal bytes 128–255, it's probably a text file in an 8-bit or variable-length ASCII-based encoding such as ISO-8859-1, UTF-8 or ASCII+Big5. If not, for some purposes you may be able to

Serializing a class which contains a std::string

寵の児 提交于 2019-12-17 02:51:47
问题 I'm not a c++ expert but I've serialized things a couple of times in the past. Unfortunately this time I'm trying to serialize a class which contains a std::string, which I understand is pretty much like serializing a pointer. I can write out the class to a file and read it back in again. All int fields are fine but the std::string field gives an "address out of bounds" error, presumably because it points to data which is no longer there. Is there a standard workaround for this? I don't want

Getting binary content in Node.js using request

夙愿已清 提交于 2019-12-17 02:21:04
问题 I was trying to GET a binary data using request, and had something like: var requestSettings = { method: 'GET', url: url, }; request(requestSettings, function(error, response, body) { // Use body as a binary Buffer } But body was always a few bytes different from expected. After further investigation I found out that request assumed body is string and replaced all non-unicode bytes. I tried to add encoding: 'binary' to requestSettings but it didn't help. How can I get the binary data? 回答1: OK

Getting binary content in Node.js using request

旧巷老猫 提交于 2019-12-17 02:20:52
问题 I was trying to GET a binary data using request, and had something like: var requestSettings = { method: 'GET', url: url, }; request(requestSettings, function(error, response, body) { // Use body as a binary Buffer } But body was always a few bytes different from expected. After further investigation I found out that request assumed body is string and replaced all non-unicode bytes. I tried to add encoding: 'binary' to requestSettings but it didn't help. How can I get the binary data? 回答1: OK

NodeJS: Saving a base64-encoded image to disk

痞子三分冷 提交于 2019-12-17 02:17:45
问题 My Express app is receiving a base64-encoded PNG from the browser (generated from canvas with toDataURL() ) and writing it to a file. But the file isn't a valid image file, and the "file" utility simply identifies it as "data". var body = req.rawBody, base64Data = body.replace(/^data:image\/png;base64,/,""), binaryData = new Buffer(base64Data, 'base64').toString('binary'); require("fs").writeFile("out.png", binaryData, "binary", function(err) { console.log(err); // writes out file without