Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:31:23+00:00 2026-05-27T17:31:23+00:00

I’m writing code that deals with a file that uses hashes. I need to

  • 0

I’m writing code that deals with a file that uses hashes. I need to read a chunk, then hash it, then write it, then read another chunk, etc.

In other words, I need to do a lot of reading and writing. I’m sure this is really simple, but I just wanted to run it by the pros…

Is it possible, and acceptable to do something like:

BinaryReader br = new BinaryReader (File.OpenRead(path));
BinaryWriter bw = new BinaryWriter (File.OpenWrite(path));
br.dostuff();
bw.dostuff();

I remember running into some sort of conflicting file streams error when experimenting with opening and writing to files, and I’m not sure what I had done to get it. Is it two file streams that’s the issue? Can I have one stream to read from and write to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:31:24+00:00Added an answer on May 27, 2026 at 5:31 pm

    This is perfecty possible and desired, A technicality, if your write method doesn’t change the length of the file and is always behind the reader, this should not give any problems. In fact, from an API point of view, this is desirable since this allows the user to control where to read from and where to write to. (It’s a recommended specification to write to a different file, in case any bad things happen during the encryption process, your input file wont be messed up).

    Something like:

    protected void Encrypt(Stream input, Stream output)
    {
        byte[] buffer = new byte[2048];
    
        while (true)
        {
            // read 
            int current = input.Read(buffer, 0, buffer.Length);
        if (current == 0)
                         break;
    
            // encrypt
            PerformActualEncryption(buffer, 0, current);
    
            // write
            output.Write(buffer, 0, current);
        }   
    }
    
    public void Main()
    {
        using (Stream inputStream  = File.Open("file.dat", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        using (Stream outputStream = File.Open("file.dat", FileMode.Open, FileAccess.Write, FileShare.ReadWrite))
        {
            Encrypt(inputStream, outputStream);
        }
    }
    

    Now since you’re using an encryption, i would even recommend to perform the actual encryption in another specialized stream. This cleans the code up nicely.

    class MySpecialHashingStream : Stream
    {
    ...
    }
    
    protected void Encrypt(Stream input, Stream output)
    {
        Stream encryptedOutput = new MySpecialHashingStream(output);
        input.CopyTo(encryptedOutput);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.