Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. splitting stream data

splitting stream data

Scheduled Pinned Locked Moved C#
help
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jtmtv18
    wrote on last edited by
    #1

    hi im just looking for a simple way to split the data of a file say 7600kb long (or any length) into x amount of 1000kb pieces. The problem im having is toward the end of the file 1000kb will not divide into 7600kb evenly. aggh another complicated problem with a easy solution that i obviously dont know the anwser to. Jesse

    D 1 Reply Last reply
    0
    • J jtmtv18

      hi im just looking for a simple way to split the data of a file say 7600kb long (or any length) into x amount of 1000kb pieces. The problem im having is toward the end of the file 1000kb will not divide into 7600kb evenly. aggh another complicated problem with a easy solution that i obviously dont know the anwser to. Jesse

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      Here's a typical stream read loop that will copy from src to dest streams:

      const int bufferSize = 4096;
      byte[] buffer = new byte[bufferSize];

      int readBytes;
      while ((readBytes = src.Read(buffer, 0, buffer.Length)) != 0)
      {
      dest.Write(buffer, 0, readBytes);
      }

      Notice what I'm doing up there: the number of bytes read will be kept on the readBytes variable. So, instead of writing bufferSize bytes (which is always 4kb), I write only what I read - although I asked to read bufferSize, sometimes, it will be lower. The loop stops reading when src.Read returns zero, as there's no more data on the stream to be read. Your algorithm will need to do something similar to this - actually, if you don't want to use a 1000Kb buffer, it'll be a bit more complicated, but I hope you got the idea. Yes, even I am blogging now!

      J 1 Reply Last reply
      0
      • D Daniel Turini

        Here's a typical stream read loop that will copy from src to dest streams:

        const int bufferSize = 4096;
        byte[] buffer = new byte[bufferSize];

        int readBytes;
        while ((readBytes = src.Read(buffer, 0, buffer.Length)) != 0)
        {
        dest.Write(buffer, 0, readBytes);
        }

        Notice what I'm doing up there: the number of bytes read will be kept on the readBytes variable. So, instead of writing bufferSize bytes (which is always 4kb), I write only what I read - although I asked to read bufferSize, sometimes, it will be lower. The loop stops reading when src.Read returns zero, as there's no more data on the stream to be read. Your algorithm will need to do something similar to this - actually, if you don't want to use a 1000Kb buffer, it'll be a bit more complicated, but I hope you got the idea. Yes, even I am blogging now!

        J Offline
        J Offline
        jtmtv18
        wrote on last edited by
        #3

        thank you very much for your time. your anwser fixed the problem with only 2 small mods. Thank you very much. Jesse The Code Project Is Your Friend...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups