function applyDelta(delta, source) {
  const reader = new BufferCursor(delta)
  const sourceSize = readVarIntLE(reader)

  if (sourceSize !== source.byteLength) {
    throw new InternalError(
      `applyDelta expected source buffer to be ${sourceSize} bytes but the provided buffer was ${source.length} bytes`
    )
  }
  const targetSize = readVarIntLE(reader)
  let target

  const firstOp = readOp(reader, source)
  // Speed optimization - return raw buffer if it's just single simple copy
  if (firstOp.byteLength === targetSize) {
    target = firstOp
  } else {
    // Otherwise, allocate a fresh buffer and slices
    target = Buffer.alloc(targetSize)
    const writer = new BufferCursor(target)
    writer.copy(firstOp)

    while (!reader.eof()) {
      writer.copy(readOp(reader, source))
    }

    const tell = writer.tell()
    if (targetSize !== tell) {
      throw new InternalError(
        `applyDelta expected target buffer to be ${targetSize} bytes but the resulting buffer was ${tell} bytes`
      )
    }
  }
  return target
}
@param {Buffer} delta
@param {Buffer} source
@returns {Buffer}