473,689 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stripping specific bytes of a file without opening the entire file...

Greetings all,

I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just
the last 512 bytes of each file. i was wondering if there is a way to
strip out this information without loading the entire file into memory.
Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the
information is, just wondering if i can somehow just open up the
trailing 512-1024 bytes. or even physically strip this info off the
file on the disc before opening it? thanks for the help. ps. im
working on a linux box, running fedora cora 2, using gcc v3.3.3

Cheers,
Adam.

Jul 23 '05 #1
7 1634

ba*****@gmail.c om wrote:
Greetings all,

I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just the last 512 bytes of each file. i was wondering if there is a way to strip out this information without loading the entire file into memory. Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the
information is, just wondering if i can somehow just open up the
trailing 512-1024 bytes. or even physically strip this info off the
file on the disc before opening it? thanks for the help. ps. im
working on a linux box, running fedora cora 2, using gcc v3.3.3

Cheers,
Adam.


Try 'istream::seekg '

Hope this helps,
-shez-

Jul 23 '05 #2

ba*****@gmail.c om wrote:
Greetings all,

I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just the last 512 bytes of each file. i was wondering if there is a way to strip out this information without loading the entire file into memory. Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the
information is, just wondering if i can somehow just open up the
trailing 512-1024 bytes. or even physically strip this info off the
file on the disc before opening it? thanks for the help. ps. im
working on a linux box, running fedora cora 2, using gcc v3.3.3

Your best bet is fseek() which allows you to position the file pointer
at a specified offset in the file. I don't think that you can avoid
opening the file in any event.

Regards,

Jon Trauntvein

Jul 23 '05 #3
yeah im trying to not open the entire file into memory. im using
fseek() once its called from fopen() but it still loads the entire
file into memory, which is a nusance. any other ideas?

Cheers,
Adam.

Jul 23 '05 #4
ff**@hotmail.co m wrote:
yeah im trying to not open the entire file into memory. im using
fseek() once its called from fopen() but it still loads the entire
file into memory, which is a nusance. any other ideas?

Cheers,
Adam.


Try using platform specific functions to prevent the loading
of the file into memory. Just remember about portability
problems.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #5

ff**@hotmail.co m wrote:
yeah im trying to not open the entire file into memory. im using
fseek() once its called from fopen() but it still loads the entire
file into memory, which is a nusance. any other ideas?

Cheers,
Adam.


Why will seek functions (either fseek() or istream::seekg( )) load the
entire file into memory? What kind of filesystem are you using? I
would think that if the filesystem provides enough information about
the physical layout of files on disk (e.g., inodes in unix), it
shouldn't need to load the entire file into memory.

Am I wrong?

-shez-

Jul 23 '05 #6
which platform specific functions are you thinking of? im running
fedora core 2 (redhat linux) on an ext3 file system. portability is
not a concern of mine. i just need it to run on ext3 filesystems.

cheers,
adam.

Jul 23 '05 #7

ff**@hotmail.co m wrote:
which platform specific functions are you thinking of? im running
fedora core 2 (redhat linux) on an ext3 file system. portability is
not a concern of mine. i just need it to run on ext3 filesystems.

cheers,
adam.


This may not help you, but I just did some tests...on my system
(winXP), using fstream to open and seekg() to move around does not
cause the file to load into memory. I tested by opening a 30MB file,
seeking around, then seeking to the begining and loading the whole
thing into memory, and seeing how long it took/how much disk usage was
required between each step. The only operation that took any
significant time was loading the file. I then tested where I just
loaded a small fraction of the file, and it took much less time than
loading the full file.

HTH

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
6026
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my use. http://www.interactivetools.com/products/htmlarea/ This only works with IE5.5+. What I need to do is to take this html formatted text and only display part of the text on a web page (much like a news article which shows only part of the...
2
2303
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I should have been quiet about it, but then I would never be reimbursed. Oh well. I have been asked to write a program to ping a NetBIOS name, get the IP, and compare the 3rd octet to a list to get the computer's location. So far, I can ping the IP,...
23
2643
by: Francesco Zavatarelli | last post by:
I downloaded a free c-compiler and I'm trying to access a file in a windows directory c:\program files\... but I get an error when I run the code. Probably my declaration char* NAME is wrong. Anybody can give a suggestion? Thanks very much. Fzavat char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB"; file_sms = fopen(NAME_SMS, "r");
8
7256
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to retrieve. But, I am having problems actually reading the data for the number of Bytes that I need to get from each address. Here is some of the code I am currently working with: Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName,...
25
2068
by: gamehack | last post by:
Hi all, I'm writing an application which will be opening binary files with definite sizes for integers(2 byte integers and 4 byte longs). Is there a portable way in being sure that each integer will be exactly 2 bytes? Should I have a platform dependent header file which checks for CHAR_BIT and sizeof(int) etc and have a few typedefs like int16, long32 etc. <OT> If I have to go non-portable, then what's the way to determine the
26
2440
by: ValK | last post by:
Hi, Here is my problem. I need to check if scanner finished scanning the document. I'm using scanner interface that came with the scanner. I tried to open file and catch IO Exception for "The process cannot access the file ....., because it is being used by another process." It worked with .PDF but not with TIF files. It will allow me to open file while scanning.
2
3037
by: Craig | last post by:
I have the need to write a byte of information to a specific location in a text file. eg. the file looks something like this. FYYNN Line 1 Line 2 <eof>
12
10664
by: Dixie | last post by:
Is there a way to shell to Microsoft Word from Access and load a specific template - using VBA? dixie
17
3535
by: broughcut | last post by:
Is it possible to fetch a specific div from a source html document using XMLHttpRequest, rather than fetching the entire file? I was going to use Ajax on mouseover but keep the normal link intact, so that if the user does not have javascript they can click the link as normal and this would take them to the new page, but if they have javascript (and ActiveX enabled I guess, in the case of IE) it would just fetch the appropriate div into...
0
8598
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9077
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8786
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.