getSnapshotBlock method

Future<GetSnapshotBlockResponse> getSnapshotBlock({
  1. required int blockIndex,
  2. required String blockToken,
  3. required String snapshotId,
})

Returns the data in a block in an Amazon Elastic Block Store snapshot.

May throw AccessDeniedException. May throw InternalServerException. May throw RequestThrottledException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ValidationException.

Parameter blockIndex : The block index of the block in which to read the data. A block index is a logical index in units of 512 KiB blocks. To identify the block index, divide the logical offset of the data in the logical volume by the block size (logical offset of data/524288). The logical offset of the data must be 512 KiB aligned.

Parameter blockToken : The block token of the block from which to get data. You can obtain the BlockToken by running the ListChangedBlocks or ListSnapshotBlocks operations.

Parameter snapshotId : The ID of the snapshot containing the block from which to get data.

Implementation

Future<GetSnapshotBlockResponse> getSnapshotBlock({
  required int blockIndex,
  required String blockToken,
  required String snapshotId,
}) async {
  _s.validateNumRange(
    'blockIndex',
    blockIndex,
    0,
    1152921504606846976,
    isRequired: true,
  );
  final $query = <String, List<String>>{
    'blockToken': [blockToken],
  };
  final response = await _protocol.sendRaw(
    payload: null,
    method: 'GET',
    requestUri:
        '/snapshots/${Uri.encodeComponent(snapshotId)}/blocks/${Uri.encodeComponent(blockIndex.toString())}',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  return GetSnapshotBlockResponse(
    blockData: await response.stream.toBytes(),
    checksum: _s.extractHeaderStringValue(response.headers, 'x-amz-Checksum'),
    checksumAlgorithm: _s
        .extractHeaderStringValue(
            response.headers, 'x-amz-Checksum-Algorithm')
        ?.let(ChecksumAlgorithm.fromString),
    dataLength:
        _s.extractHeaderIntValue(response.headers, 'x-amz-Data-Length'),
  );
}