| Index: components/filesystem/file_impl.cc
|
| diff --git a/components/filesystem/file_impl.cc b/components/filesystem/file_impl.cc
|
| index 8a3682b075e0c20bb1bc26b5edb4054be7b95877..da156c8618c7a3e0c5e378d8cf554dedec12e11f 100644
|
| --- a/components/filesystem/file_impl.cc
|
| +++ b/components/filesystem/file_impl.cc
|
| @@ -92,6 +92,28 @@
|
| DCHECK_LE(static_cast<size_t>(num_bytes_read), num_bytes_to_read);
|
| bytes_read.resize(static_cast<size_t>(num_bytes_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 int kBufferSize = 1 << 16;
|
| + 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.
|
|
|