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 7516311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:05:20+00:00 2026-05-30T01:05:20+00:00

I’m trying to split up data into little packets. I’m not exactly sure how

  • 0

I’m trying to split up data into little packets. I’m not exactly sure how this read method is suppose to work but I’ve given a buffer size of 512 to read from the file.
But instead of getting 512 i just get 5 in my first packet. Others vary from 0 to above 512 ( which shouldn’t happen).

It’s a zip file I’m trying to split up:
In text the first few bytes look like this

text
(de bucket like characters are actually 2 characters)

It seems to grab the first 5 bytes as it should but afterwards just stops and goes to the next read block.

Since it’s a buffer of 512 everything after the first 5 bytes is garbage.
I’m using an ifstream. And the mode is set to Binary.

Any suggestions?

void FileProcessor::send()
{
    //If no file is opened return
    if(!_file.is_open()) return;
    //Reset position to beginning
    _file.seekg(0, ios::beg);

    //Result buffer
    char * buffer;
    char * partBytes = new char[_bufferSize];

    //Read the file and send it over the network
    while (_file.read(partBytes, _bufferSize))
    {

        buffer = Packet::create(Packet::FILE,partBytes);
        Packet *p = Packet::create(buffer);
        //cout <<  strlen(partBytes);
        //p->PrintHex(buffer,_bufferSize+Packet::HeaderSize);

        //break;
        cout << "Normal size : \t" << strlen(partBytes)<< "\tPacketSize: \t" << p->getLength()<<"\n";
        //cout << strcmp(p->getData().c_str(),partBytes) << "\n";
        writeToFile(p->getData().c_str(),p->getData().length());
        delete p;
    }
    //Write final bytes if any
    if(_file.gcount())
    {
        //writeToFile(partBytes, _file.gcount());


        buffer = Packet::create(Packet::FILE,partBytes);
        Packet *p = Packet::create(buffer);

        writeToFile(p->getData().c_str(),p->getData().length());
        //cout << p->getLength() << "\n";
        delete p;

    }   

    //cout<< *p << "\n";
    delete [] partBytes;
}

Im just testing a direct read write right now.

  • 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-30T01:05:23+00:00Added an answer on May 30, 2026 at 1:05 am

    Inside your loop, instead of assuming it always reads a full buffer of data, use gcount() to find how many it actually read, and transmit that many.

    I feel obliged to add that this:

        buffer = Packet::create(Packet::FILE,partBytes);
        Packet *p = Packet::create(buffer);
    

    looks quite strange to me. Not sure it’s wrong, but it’s not immediately obvious that it’s right either (and if it is right, the design seems a bit odd).

    I’d also skip the dynamic allocation and deletion:

    char * partBytes = new char[_bufferSize];
    // ...
    delete [] partBytes;
    

    and use a std::vector<char> instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
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.