| 341 | } |
| 342 | |
| 343 | Status S3FileSystem::NewAppendableFile(const string& fname, |
| 344 | std::unique_ptr<WritableFile>* result) { |
| 345 | std::unique_ptr<RandomAccessFile> reader; |
| 346 | TF_RETURN_IF_ERROR(NewRandomAccessFile(fname, &reader)); |
| 347 | std::unique_ptr<char[]> buffer(new char[kS3ReadAppendableFileBufferSize]); |
| 348 | Status status; |
| 349 | uint64 offset = 0; |
| 350 | StringPiece read_chunk; |
| 351 | |
| 352 | string bucket, object; |
| 353 | TF_RETURN_IF_ERROR(ParseS3Path(fname, false, &bucket, &object)); |
| 354 | result->reset(new S3WritableFile(bucket, object, this->GetS3Client())); |
| 355 | |
| 356 | while (true) { |
| 357 | status = reader->Read(offset, kS3ReadAppendableFileBufferSize, &read_chunk, |
| 358 | buffer.get()); |
| 359 | if (status.ok()) { |
| 360 | (*result)->Append(read_chunk); |
| 361 | offset += kS3ReadAppendableFileBufferSize; |
| 362 | } else if (status.code() == error::OUT_OF_RANGE) { |
| 363 | (*result)->Append(read_chunk); |
| 364 | break; |
| 365 | } else { |
| 366 | (*result).reset(); |
| 367 | return status; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return Status::OK(); |
| 372 | } |
| 373 | |
| 374 | Status S3FileSystem::NewReadOnlyMemoryRegionFromFile( |
| 375 | const string& fname, std::unique_ptr<ReadOnlyMemoryRegion>* result) { |