public int StoreSnapshot( IReadOnlyCollection <Blob> blobs, Fuzzy scanFuzzy, DateTime creationTimeUtc, Func <string, Stream> openRead) { var newSnapshot = new Snapshot( _currentSnapshotId == null ? 0 : _currentSnapshotId.Value + 1, creationTimeUtc, WriteBlobs(blobs, scanFuzzy, openRead)); using var memoryStream = new MemoryStream( DataConvert.ObjectToBytes(newSnapshot)); var newSnapshotReference = new SnapshotReference( _salt, _iterations, WriteContent(AesGcmCrypto.GenerateNonce(), memoryStream)); _intRepository.StoreValue( newSnapshot.SnapshotId, DataConvert.ObjectToBytes(newSnapshotReference)); _currentSnapshotId = newSnapshot.SnapshotId; _probe.StoredSnapshot(newSnapshot.SnapshotId); return(newSnapshot.SnapshotId); }
private Snapshot GetSnapshot( int snapshotId, SnapshotReference snapshotReference) { try { using var memoryStream = new MemoryStream(); RetrieveContent( snapshotReference.ContentUris, memoryStream); return(DataConvert.BytesToObject <Snapshot>( memoryStream.ToArray())); } catch (ChunkyardException) { throw; } catch (Exception e) { throw new ChunkyardException( $"Could not read snapshot: #{snapshotId}", e); } }