public bool TryAddPiece(FileSliceModel slice) { if (this.stream.Position > slice.Start) { return(false); } this.stream.Position = slice.Start; this.stream.Write(slice.Piece, 0, slice.End - slice.Start); if (slice.FileSize == slice.End) { this.stream.Close(); this.OnComplete?.Invoke(this); } return(true); }
public IActionResult HandleFilePiece(FileSliceModel fileSlice) { if (fileSlice.IsIntegral) { bool isSucceeded = this.resumeFile.TryAddPiece(fileSlice); if (isSucceeded) { return(Ok()); } else { _logger.LogError("Fail to write file piece."); return(NotFound()); } } else { _logger.LogError("File piece is mutated."); return(NotFound()); } }