binaryfiles

Why is (foobar>>x) preferred over (! foobar.eof() ) [duplicate]

佐手、 提交于 2019-12-05 20:26:42
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Why is iostream::eof inside a loop condition considered wrong? eof() bad practice? My teacher said we shouldn't use EOF to read in text file or binary file information instead we should use (afile>>x). He didn't explain why, can someone explain to me. Can someone also explain what are the differences in this two different method of reading //Assuming declaration //ifstream foobar ( ! foobar.eof() ) { foobar>>x;

Identifying the type of a file without extension from binary data

感情迁移 提交于 2019-12-05 19:16:04
I have some files without extension. I would like associate extensions to them. For that I have written a python program to read the data in the file. My doubt is how can I identify its type without the extension without using third party tools. I have to identify a pdf, doc and text file only. Other type of files are not possible. My server is cent os You could read the first few bytes of the file and look for a "magic number". The Wikipedia page on magic numbers suggests that PDF files begin with ASCII %PDF and doc files begin with hex D0 CF 11 E0. Identifying text files is going be pretty

What is “Alignment” field in binary formats? Why is it needed?

本小妞迷上赌 提交于 2019-12-05 17:43:41
In ELF file format we have an Alignment field in Segment Header Table aka Program Header Table . In case of Windows PE file format they take it to next level the Sections have two alignment values, one within the disk file and the other in memory. The PE file header specifies both of these values. I didn't understand a thing about this alignment. What do we need it for? How & Where is it used? Again, I don't know what is alignment in binary file format context but why do we need it? Well, alignment is usually stretching the storage size of some value to occupy some "round" space, like 32, 64,

Difference in writing string vs. char array with System.IO.BinaryWriter

十年热恋 提交于 2019-12-05 17:19:01
I’m writing text to a binary file in C# and see a difference in quantity written between writing a string and a character array. I’m using System.IO.BinaryWriter and watching BinaryWriter.BaseStream.Length as the writes occur. These are my results: using(BinaryWriter bw = new BinaryWriter(File.Open(“data.dat”), Encoding.ASCII)) { string value = “Foo”; // Writes 4 bytes bw.Write(value); // Writes 3 bytes bw.Write(value.ToCharArray()); } I don’t understand why the string overload writes 4 bytes when I’m writing only 3 ASCII characters. Can anyone explain this? The documentation for BinaryWriter

Is it possible to write an binary file import extension for vs code?

一世执手 提交于 2019-12-05 14:26:08
I want to display some informations of a binary file in vs code. Is it possible to write an extension for vs code, such that when selecting that file in the Explorer (or opening it directly) you see some text extracted from the binary file by that extension? So the core functionality of that extension would be (simplified) a binary to text converter. Any suggestions? The VS Code team member has confirmed they do not have support for registering content providers for binary files in my issue . I've inspected the workspace.onDidOpenTextDocument and window.onDidChangeActiveTextEditor APIs, but

Segfault while using mmap in C for reading binary files

◇◆丶佛笑我妖孽 提交于 2019-12-05 14:07:20
I am trying to use mmap in C just to see how it exactly works. Currently I am try to read a binary file byte by byte using mmap. My code is like this: #include <unistd.h> #include <sys/types.h> #include <sys/mman.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> int main(int argc, char *argv[]) { int fd; char *data; for ( int i = 1; i<argc; i++) { if(strcmp(argv[i],"-i")==0) fd = open(argv[i+1],O_RDONLY); } data = mmap(NULL, 4000, PROT_READ, MAP_SHARED, fd, 8000); int i = 0; notation = data [i]; // ...... } My problem occurs when I try notation = data[0] and I get a segfault . I am

Convert any file into a binary file and vice versa

与世无争的帅哥 提交于 2019-12-05 13:16:34
I've searched in StackOverFlow website and over the internet for this question and its relevant questions but I still haven't got a clear answer. I want to know what software may I use to convert any file (regarding size) into a text file that contains zeros and ones (only) of this specific file, then convert this text file that contains these zeros and ones back to the original file. Execuse my ignorance if the files that contains zeros and ones are not called "binary files", I searched the internet and read in wikipedia there are software called [hex dump], I don't need those, I need what I

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

依然范特西╮ 提交于 2019-12-05 12:17:18
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? Edit: I'm using Python 2.6 >>> data = 'S\x00e\x00r\x00i\x00e\x00s\x00' >>> data.decode('utf-16') u'Series

Why is the git index file binary?

做~自己de王妃 提交于 2019-12-05 11:52:58
Most of the files in my Git directory are plain text files (except for the compressed loose objects and the packfiles). So I can just cat and edit files like .git/HEAD or .git/refs/heads/master and inspect the repository if it gets corrupted. But the .git/index is a binary file. Wouldn't a plain text file be more useful because it can easily be modified by hand? Scott Chacon shows in his presentation the following image (Slide 278): In my opinion, this can easily be put to a plain text file. So why is it a binary file rather than a plain text file? VonC The index, as presented in " What does

How to display binary images from Database to edit form using MVC 4

…衆ロ難τιáo~ 提交于 2019-12-05 10:48:20
I am storing images in Database as Binary Images successfully. I want to display these images in Edit form to modify and save changes. System.OutOfMemoryException' was thrown in Edit.cshtml form while displaying Binary Images from Database. Can someone please correct my code. Model class: public class Accommodation { [Key] public string A_Unique_Id { get; set; } public byte[] Picture1 { get; set; } public byte[] Picture2 { get; set; } public byte[] Picture3 { get; set; } } // GET: /Accommodation/Edit/5 public ActionResult Edit(string id) { Accommodation accommodation = db.Accommodation.Find(id