Skip to content

Commit 56e707c

Browse files
samples(storage): use istreambuf_iterator instead of istream_iterator in storage_object_samples (#15059)
istream_iterator skips whitespace by default which results in data not being read as-is when it has whitespace symbols/bytes in it. Co-authored-by: Denis DelGrosso <[email protected]>
1 parent fc70c16 commit 56e707c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

google/cloud/storage/examples/storage_object_samples.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ void ReadObjectIntoMemory(google::cloud::storage::Client client,
322322
[](gcs::Client client, std::string const& bucket_name,
323323
std::string const& object_name) {
324324
gcs::ObjectReadStream stream = client.ReadObject(bucket_name, object_name);
325-
std::string buffer{std::istream_iterator<char>(stream),
326-
std::istream_iterator<char>()};
325+
std::string buffer{std::istreambuf_iterator<char>(stream),
326+
std::istreambuf_iterator<char>()};
327327
if (stream.bad()) throw google::cloud::Status(stream.status());
328328

329329
std::cout << "The object has " << buffer.size() << " characters\n";
@@ -340,7 +340,7 @@ void ReadObjectGzip(google::cloud::storage::Client client,
340340
std::string const& object_name) {
341341
auto is =
342342
client.ReadObject(bucket_name, object_name, gcs::AcceptEncodingGzip());
343-
auto const contents = std::string{std::istream_iterator<char>(is), {}};
343+
auto const contents = std::string{std::istreambuf_iterator<char>(is), {}};
344344
if (is.bad()) throw google::cloud::Status(is.status());
345345
std::cout << "The object has " << contents.size() << " characters\n";
346346
}

0 commit comments

Comments
 (0)