Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMMON: Add WriteStream::writeStream() #1998

Open
wants to merge 1 commit into
base: master
from

Conversation

@ccawley2011
Copy link
Member

ccawley2011 commented Jan 12, 2020

No description provided.

@dreammaster

This comment has been minimized.

Copy link
Member

dreammaster commented Jan 12, 2020

That could indeed be a nice little helper. A few comments I have:

  1. It wouldn't hurt to return the bytes written as a result from the method, just like the write method does
  2. It may not hurt to have a second overloaded version of the method that simply takes in a SeekableReadStream and no size, and simply chains to the writeStream method with the stream and stream size. That way, callers that want to copy an entire stream don't have to explicitly specify the size, so long as it's a seekable one (which implements the size() method).
@@ -28,6 +28,14 @@

namespace Common {

void WriteStream::writeStream(ReadStream *stream, uint32 dataSize) {
void *buf = malloc(dataSize);

This comment has been minimized.

Copy link
@bgK

bgK Jan 12, 2020

Member

Typically data copying routines use some kind of buffer of a fixed size as temporary storage so that they can work on arbitrarily sized inputs. See what boost does for example:
https://github.com/boostorg/iostreams/blob/develop/include/boost/iostreams/copy.hpp#L123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.