binary-data

How does pack() and unpack() work in Ruby

旧巷老猫 提交于 2019-12-18 12:38:57
问题 In Ruby why we need array Packing ? How does directive help to do such packing? I ran some code in my console to see what and how directives looks like in Array packing.But the output is closely same with each directives. Then in core how they differs? irb(main):003:0> n = [ 65, 66, 67 ] => [65, 66, 67] irb(main):004:0> n.pack("ccc") => "ABC" irb(main):005:0> n.pack("C") => "A" irb(main):006:0> n.pack("CCC") => "ABC" irb(main):007:0> n.pack("qqq") => "A\x00\x00\x00\x00\x00\x00\x00B\x00\x00

Compile a binary file for linking OSX

空扰寡人 提交于 2019-12-18 12:37:23
问题 I'm trying to compile a binary file into a MACH_O object file so that it can be linked it into a dylib. The dylib is written in c/c++. On linux the following command is used: ld -r -b binary -o foo.o foo.bin I have tried various option on OSX but to no avail: ld -r foo.bin -o foo.o gives: ld: warning: -arch not specified ld: warning: ignoring file foo.bin, file was built for unsupported file format which is not the architecture being linked (x86_64) An empty .o file is created ld -arch x86_64

How to output binary data to a file in Java?

回眸只為那壹抹淺笑 提交于 2019-12-18 11:09:09
问题 I'm trying to write data to a file in binary format for compression. The data consists entirely of floating points so I decided to quantize the data to an intergers between 0 and 65535 so the data can be written as two bit unsigned integers and ultimately save space. However, I need to output that quantized data to a file in binary instead of human-readable Ascii. At the moment this is what I'm doing @param outputFile the file containing the already quantized data as strings in a .txt file

Writing Data to an OutputStream with Swift 5+

百般思念 提交于 2019-12-18 09:34:38
问题 This code used to be fine (in the sense that the compiler didn't complain): extension OutputStream { func write(_ data: Data) -> Int { return data.withUnsafeBytes { pointer in return self.write(pointer, maxLength: data.count) } } } Since Swift 5.0, this produces a warning: Warning: 'withUnsafeBytes' is deprecated: use withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R instead I tried using the proposed method but I can't seem to wrangle the UnsafeRawBufferPointer into

Reading binary image data from a web service into UIImage

一世执手 提交于 2019-12-17 13:22:56
问题 I'm consuming a web service in my iPhone app. The web service method returns a response which has several fields (eg. ID, Description, etc..). One of these fields contains binary image data which I need to convert to UIImage in my iPhone application. I'm using a NSXMLParser successfully to extract data from the XML response. In the parser:foundCharacters: selector of the XMLParser, it gives a NSString* pointing to the string within each field. Since this is a string, this is what I do to read

Best way to read a large file into a byte array in C#?

你离开我真会死。 提交于 2019-12-17 02:52:28
问题 I have a web server which will read large binary files (several megabytes) into byte arrays. The server could be reading several files at the same time (different page requests), so I am looking for the most optimized way for doing this without taxing the CPU too much. Is the code below good enough? public byte[] FileToByteArray(string fileName) { byte[] buff = null; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); long numBytes

How to read text from the BLOB format?

好久不见. 提交于 2019-12-14 02:32:45
问题 I am saving pdf/word documents in DB by saving them in blob format. Now I want to read it as string. My intention is just to read saved blob content as string, so that I can search for text. For example: If few different types of documents are uploaded and I want to search for a text into it. Ho it can be achieved ? Thanks in advance. 回答1: First of all, BLOB is a BINARY LOB and You used it correctly - to store tha files into a database. As it is BINARY also the data in this column is stored

What does it mean if binary data is “4 byte single format” and how do I read it in JavaScript?

末鹿安然 提交于 2019-12-13 21:36:48
问题 I have to read a binary file which is said to be encoded 4 byte single format and never having to work with binary data, I don't know what this means. I can do this reading a file with binary data in JavaScript: d = new FileReader(); d.onload = function (e) { var i, len; // grab a "chunk" response_buffer = e.target.result.slice(0, 1024); view = new DataView(response_buffer); for (i = 0, len = response_buffer.byteLength; i < len; i += 1) { // hmhm console.log(view.getUint8(i)); } } d

convert binary data to base-64 javaScript

和自甴很熟 提交于 2019-12-13 16:32:11
问题 I have a problem to convert binary data to base-64 in JS. I try all the things that exists on the net include this How to parse into base64 string the binary image from response?, but everyone return a wrong base-64 and I don't find why ! **I try this solution Retrieving binary file content using Javascript, base64 encode it and reverse-decode it using Python but the convert to base-64 not work for me! It's return something wrong . I get a string binary response from server and I want to

SWIG unsigned char and byte[]

China☆狼群 提交于 2019-12-13 15:10:58
问题 I've looked all over the place. I have tried some of the techniques on this site. To no avail. I have a c++ global function char* squid( char* buff, int len ); I create a .i file %module Crabby %include "arrays_java.i" %{ /* headers here are included in the wrapper code */ #include "sponge.h" %} %typemap(jtype) (const signed char *arr, size_t sz) "byte[]" %typemap(jstype) (const signed char *arr, size_t sz) "byte[]" %typemap(jni) (const signed char *arr, size_t sz) "jbyteArray" %typemap