Support streaming for lz4 recompress

This reduces peak memory usage of update_engine from
~700MB to ~400MB. As we no longer need to cache the entire patched
blocks in memory, data are written to disk as they come.

Test: th
Change-Id: I7b353dbaee4ee63e984ec2014476e3d27387e0fc
diff --git a/payload_consumer/block_extent_writer.cc b/payload_consumer/block_extent_writer.cc
index 6b1fba7..055b485 100644
--- a/payload_consumer/block_extent_writer.cc
+++ b/payload_consumer/block_extent_writer.cc
@@ -42,8 +42,9 @@
 
   if (buffer_.empty() && count >= cur_extent_size) {
     if (!WriteExtent(data, cur_extent, block_size_)) {
-      LOG(ERROR) << "WriteExtent(" << cur_extent.start_block() << ", " << data
-                 << ", " << cur_extent_size << ") failed.";
+      LOG(ERROR) << "WriteExtent(" << cur_extent.start_block() << ", "
+                 << static_cast<const void*>(data) << ", " << cur_extent_size
+                 << ") failed.";
       // return value is expected to be greater than 0. Return 0 to signal error
       // condition
       return 0;
diff --git a/payload_consumer/install_operation_executor.cc b/payload_consumer/install_operation_executor.cc
index 5318cc3..69ef9c1 100644
--- a/payload_consumer/install_operation_executor.cc
+++ b/payload_consumer/install_operation_executor.cc
@@ -268,12 +268,18 @@
     size_t count) {
   brillo::Blob src_data;
 
-  brillo::Blob dst_data;
   TEST_AND_RETURN_FALSE(utils::ReadExtents(
       source_fd, operation.src_extents(), &src_data, block_size_));
-  TEST_AND_RETURN_FALSE(
-      Lz4Patch(ToStringView(src_data), ToStringView(data, count), &dst_data));
-  return writer->Write(dst_data.data(), dst_data.size());
+  TEST_AND_RETURN_FALSE(Lz4Patch(
+      ToStringView(src_data),
+      ToStringView(data, count),
+      [writer(writer.get())](const uint8_t* data, size_t size) -> size_t {
+        if (!writer->Write(data, size)) {
+          return 0;
+        }
+        return size;
+      }));
+  return true;
 }
 
 bool InstallOperationExecutor::ExecuteSourceBsdiffOperation(