pub fn add_piece<R, W>(
    source: R,
    target: W,
    piece_size: UnpaddedBytesAmount,
    piece_lengths: &[UnpaddedBytesAmount]
) -> Result<(PieceInfo, UnpaddedBytesAmount)> where
    R: Read,
    W: Write
Expand description

Computes a NUL-byte prefix and/or suffix for source using the provided piece_lengths and piece_size (such that the source, after preprocessing, will occupy a subtree of a merkle tree built using the bytes from target), runs the resultant byte stream through the preprocessor, and writes the result to target. Returns a tuple containing the number of bytes written to target (source plus alignment) and the commitment.

WARNING: Depending on the ordering and size of the pieces in piece_lengths, this function could write a prefix of NUL bytes which wastes ($SIZESECTORSIZE/2)-$MINIMUM_PIECE_SIZE space. This function will be deprecated in favor of write_and_preprocess, and miners will be prevented from sealing sectors containing more than $TOOMUCH alignment bytes.

Arguments

  • source - a readable source of unprocessed piece bytes.
  • target - a writer where we will write the processed piece bytes.
  • piece_size - the number of unpadded user-bytes which can be read from source before EOF.
  • piece_lengths - the number of bytes for each previous piece in the sector.