@@ -466,10 +466,8 @@ class ObjectInputFile final : public io::RandomAccessFile {
466466
467467Status CreateEmptyBlockBlob (
468468 std::shared_ptr<Azure::Storage::Blobs::BlockBlobClient> block_blob_client) {
469- std::string s = " " ;
470469 try {
471- block_blob_client->UploadFrom (
472- const_cast <uint8_t *>(reinterpret_cast <const uint8_t *>(s.data ())), s.size ());
470+ block_blob_client->UploadFrom (nullptr , 0 );
473471 } catch (const Azure::Storage::StorageException& exception) {
474472 return internal::ExceptionToStatus (
475473 " UploadFrom failed for '" + block_blob_client->GetUrl () +
@@ -624,23 +622,22 @@ class ObjectAppendStream final : public io::OutputStream {
624622 Status DoAppend (const void * data, int64_t nbytes,
625623 std::shared_ptr<Buffer> owned_buffer = nullptr ) {
626624 RETURN_NOT_OK (CheckClosed (" append" ));
627- auto append_data = reinterpret_cast <uint8_t *>((void *)data);
628- auto block_content = Azure::Core::IO::MemoryBodyStream (
629- append_data, strlen (reinterpret_cast <char *>(append_data)));
625+ auto append_data = reinterpret_cast <const uint8_t *>(data);
626+ auto block_content = Azure::Core::IO::MemoryBodyStream (append_data, nbytes);
630627 if (block_content.Length () == 0 ) {
631628 return Status::OK ();
632629 }
633630
634- auto size = block_ids_.size ();
631+ const auto n_block_ids = block_ids_.size ();
635632
636- // New block ids must always be distinct from the existing block ids . Otherwise we
633+ // New block ID must always be distinct from the existing block IDs . Otherwise we
637634 // will accidentally replace the content of existing blocks, causing corruption.
638635 // We will use monotonically increasing integers.
639- std::string new_block_id = std::to_string (size );
636+ std::string new_block_id = std::to_string (n_block_ids );
640637
641638 // Pad to 5 digits, because Azure allows a maximum of 50,000 blocks.
642639 const size_t target_number_of_digits = 5 ;
643- int required_padding_digits =
640+ const auto required_padding_digits =
644641 target_number_of_digits - std::min (target_number_of_digits, new_block_id.size ());
645642 new_block_id.insert (0 , required_padding_digits, ' 0' );
646643 new_block_id += " -arrow" ; // Add a suffix to reduce risk of block_id collisions with
@@ -669,7 +666,7 @@ class ObjectAppendStream final : public io::OutputStream {
669666 return CommitBlockList (block_blob_client_, block_ids_, metadata_);
670667 }
671668
672- protected :
669+ private :
673670 std::shared_ptr<Azure::Storage::Blobs::BlockBlobClient> block_blob_client_;
674671 const io::IOContext io_context_;
675672 const AzureLocation location_;
@@ -956,17 +953,17 @@ class AzureFileSystem::Impl {
956953 blob_service_client_->GetBlobContainerClient (location.container )
957954 .GetBlockBlobClient (location.path ));
958955
959- std::shared_ptr<ObjectAppendStream> ptr ;
956+ std::shared_ptr<ObjectAppendStream> stream ;
960957 if (truncate) {
961958 RETURN_NOT_OK (CreateEmptyBlockBlob (block_blob_client));
962- ptr = std::make_shared<ObjectAppendStream>(block_blob_client, fs->io_context (),
959+ stream = std::make_shared<ObjectAppendStream>(block_blob_client, fs->io_context (),
963960 location, metadata, options_, 0 );
964961 } else {
965- ptr = std::make_shared<ObjectAppendStream>(block_blob_client, fs->io_context (),
962+ stream = std::make_shared<ObjectAppendStream>(block_blob_client, fs->io_context (),
966963 location, metadata, options_);
967964 }
968- RETURN_NOT_OK (ptr ->Init ());
969- return ptr ;
965+ RETURN_NOT_OK (stream ->Init ());
966+ return stream ;
970967 }
971968};
972969
0 commit comments