Chromium Code Reviews| Index: components/filesystem/file_impl.cc |
| diff --git a/components/filesystem/file_impl.cc b/components/filesystem/file_impl.cc |
| index 1d6b7e208390e233ec8b6b451678de2acc077dd7..3df0072ca35d6af935e0c808155c53c027cd9b27 100644 |
| --- a/components/filesystem/file_impl.cc |
| +++ b/components/filesystem/file_impl.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/logging.h" |
| #include "build/build_config.h" |
| #include "components/filesystem/util.h" |
| +#include "mojo/common/common_type_converters.h" |
| #include "mojo/platform_handle/platform_handle_functions.h" |
| static_assert(sizeof(off_t) <= sizeof(int64_t), "off_t too big"); |
| @@ -93,6 +94,28 @@ void FileImpl::Read(uint32_t num_bytes_to_read, |
| callback.Run(FileError::OK, std::move(bytes_read)); |
| } |
| +void FileImpl::ReadEntireFile(const ReadEntireFileCallback& callback) { |
| + if (!file_.IsValid()) { |
| + callback.Run(GetError(file_), mojo::Array<uint8_t>()); |
| + return; |
| + } |
| + |
| + // Seek to the front of the file. |
| + if (file_.Seek(base::File::FROM_BEGIN, 0) == -1) { |
| + callback.Run(FileError::FAILED, mojo::Array<uint8_t>()); |
| + return; |
| + } |
| + |
| + std::string contents; |
| + const size_t kBufferSize = 1 << 16; |
|
sky
2016/01/22 22:21:13
Doesn't ReadAtCurrentPos take and return ints? In
|
| + scoped_ptr<char[]> buf(new char[kBufferSize]); |
| + size_t len; |
| + while ((len = file_.ReadAtCurrentPos(buf.get(), kBufferSize)) > 0) |
| + contents.append(buf.get(), len); |
| + |
| + callback.Run(FileError::OK, mojo::Array<uint8_t>::From(contents)); |
| +} |
| + |
| // TODO(vtl): Move the implementation to a thread pool. |
| void FileImpl::Write(mojo::Array<uint8_t> bytes_to_write, |
| int64_t offset, |