I have only 1GB of RAM so I cannot work with files too big with the ReadtoEnd method.
Here is the code Im trying so that the file would split in pieces of 256MB: - Try
-
Dim BInput As New FileStream(Filename, FileMode.Open, FileAccess.Read)
-
Dim Reader As New BinaryReader(BInput)
-
-
Dim info As New FileInfo(Filename)
-
totalSize = info.Length
-
Dim i As Integer = totalSize / Dtblock 'Dtblock is a const 256mb
-
Dim completed As Integer = 0
-
-
Dim firstround As Boolean = True
-
-
If (totalSize > Dtblock) Then
-
'The file is bigger then 256MB
-
'Prepare to split
-
Dim EngineObj As New Engine()
-
ReDim buffer(Dtblock)
-
-
While completed < totalSize
-
-
Reader.Read(buffer, completed, completed + Dtblock)
-
'..
-
'here I work with the buffer, then I have to save it
-
'..
-
-
completed += Dtblock + 1
-
-
If firstround Then 'here I check if I should create or append to output
-
'Write
-
firstround = False
-
Dim BOutput As New FileStream(TxtBoxOutput.Text, FileMode.Create, FileAccess.Write)
-
Dim writer As New BinaryWriter(BOutput)
-
writer.Write(buffer)
-
Else
-
'Append
-
Dim BOutput As New FileStream(TxtBoxOutput.Text, FileMode.Append, FileAccess.Write)
-
Dim writer As New BinaryWriter(BOutput)
-
writer.Write(buffer)
-
End If
-
-
End While
-
-
Else
-
'The file is smaller then 256MB
-
-
ReDim buffer(totalSize)
-
Reader.Read(buffer, 0, totalSize)
-
..
-
'Here I work with the buffer..
-
..
-
'Write buffer to new file
-
Dim BOutput As New FileStream(TxtBoxOutput.Text, FileMode.Create, FileAccess.Write)
-
Dim writer As New BinaryWriter(BOutput)
-
writer.Write(buffer)
-
'Done, close instances of file streams
-
Reader.Close()
-
writer.Close()
-
-
End If
-
-
BInput.Dispose()
-
MessageBox.Show("Operation finished!")
-
Catch ex As Exception
-
MessageBox.Show(ex.ToString)
-
End Try
I know it might be horrible, but its the only idea I came up with.
anyone knows a better way to accomplish this?
Or if somebody find knows why I always get an exception on the "Reader.Read(buffer, completed, completed + Dtblock)" saying :
"Offset and length for the array lie outside of the valid field, or the number is greater than the number of the elements of the index to at the end of the source listing."
would be even better..
but till now I dont know why that happens because I supposed that the parameters for Read was like this:
Read(<WheretoStore>,<starting point>, <how many to read from starting point>)
correct?
4 2021 TRScheel 638
Recognized Expert Contributor
I am not sure, but I think the error is because when you read, you move the start location of the read. For example: - The dog jumped over the moon
If you wrote:
You would get 'The'
If you did it again, you would get ' do'. But if instead you did:
you would get 'og '
This is all purely speculation, a short test should prove this wrong/right.
Hey!
thank you very much for your reply.
you were right about the Read's parameter.
I just didnt know that it had an internal pointer that keeps track of the last byte processed ;)
thanks again!
later,
Thiago.
TRScheel 638
Recognized Expert Contributor
No problem, glad to have helped.
Plater 7,872
Recognized Expert Expert
For Read the paremters are:
[number of bytes actually read] Read( [name of byte[] you want the data to go into], [starting index in the GIVEN byte[] (the previous parameter)], [total number of bytes to attempt to read] );
so if I wanted to try to read 1024 bytes into a buffer starting at the first index in my array I woul do this: -
Byte[] buff=new Byte[1024];
-
int actualread=-1;
-
actaulread=mystream.Read(buff,0,buff.Length);
-
//actualread will be set to how many bytes I actually was able to read, or 0 if end of stream
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brian |
last post by:
I'm having intermittent trouble with a call to the Read method of
the HttpWebResponse object. I get an ArumentOutOfRangeException
claiming that deep down inside of the Read method, the count...
|
by: Junior |
last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could
not be found (are you missing a using directive or an assembly reference?)"
message in two particular lines, and I've...
|
by: Tim |
last post by:
Hi,
I'm experiencing some problem with the following code:
st = File.Open(sFilename, FileMode.Open, FileAccess.ReadWrite)
br = New BinaryReader(st)
Do Until br.PeekChar = -1
Dim buffer()...
|
by: David Buchan |
last post by:
Hello,
I wonder if anyone could help me.
I'm using vb.NET and I'd like to read a binary file, byte by byte, and
then write to another file (making a duplicate, identical file).
I'd then...
|
by: Craig Buchanan |
last post by:
when i try to open a file that has been compressed with GZipStream (source
from microsoft's 101 Samples for Visual Studio 2005), i get an "invalid
archive" message from winzip, zipgenius and xp's...
| |
by: chenatcr |
last post by:
Hello,
I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined...
|
by: duclm |
last post by:
Hi all,
II am having problem sending zip file(binary file) using webrequest function from wince5.0 device to a webpage. It works fine for any file with size less than or equal to 1.5kb. Any bigger...
|
by: WeCi2i |
last post by:
Okay, I have a problem that has been stumping me for weeks. I have tried many different solutions and this is pretty much my last resort. I have seen a lot of good answers give here so I figured I...
|
by: Lambda |
last post by:
I'd like to write compressed data to a file.
To improve performance, I want to use buffer.
I read some books, they all talk about 'character' stream.
But I think compressed data should be...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
| |
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| | |