Fix File.Open

This commit is contained in:
Genteure 2021-05-21 21:04:37 +08:00
parent cc32fbc86c
commit ba847cf28d
4 changed files with 7 additions and 7 deletions

View File

@ -265,7 +265,7 @@ namespace BililiveRecorder.Core.Recording
this.OnNewFile = onNewFile ?? throw new ArgumentNullException(nameof(onNewFile));
}
public (Stream stream, object state) CreateOutputStream()
public (Stream stream, object? state) CreateOutputStream()
{
var paths = this.task.CreateFileName();
@ -290,7 +290,7 @@ namespace BililiveRecorder.Core.Recording
{ Directory.CreateDirectory(Path.GetDirectoryName(path)); }
catch (Exception) { }
var stream = new FileStream(path, FileMode.Append, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var stream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read);
return stream;
}
}

View File

@ -4,7 +4,7 @@ namespace BililiveRecorder.Flv
{
public interface IFlvWriterTargetProvider
{
(Stream stream, object state) CreateOutputStream();
(Stream stream, object? state) CreateOutputStream();
Stream CreateAlternativeHeaderStream();
}

View File

@ -312,16 +312,16 @@ namespace BililiveRecorder.ToolBox.Commands
public Stream CreateAlternativeHeaderStream()
{
var path = Path.ChangeExtension(this.pathTemplate, "header.txt");
return File.Open(path, FileMode.Append, FileAccess.Write, FileShare.None);
return new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read);
}
public (Stream stream, object state) CreateOutputStream()
public (Stream stream, object? state) CreateOutputStream()
{
var i = this.fileIndex++;
var path = Path.ChangeExtension(this.pathTemplate, $"fix_p{i:D3}.flv");
var fileStream = File.Open(path, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
BeforeFileOpen?.Invoke(this, path);
return (fileStream, null!);
return (fileStream, null);
}
}
}

View File

@ -21,7 +21,7 @@ namespace BililiveRecorder.Flv.UnitTests.Grouping
public class TestOutputProvider : IFlvWriterTargetProvider
{
public Stream CreateAlternativeHeaderStream() => throw new NotImplementedException();
public (Stream, object) CreateOutputStream() => (File.Open(Path.Combine(TEST_OUTPUT_PATH, DateTimeOffset.Now.ToString("s").Replace(':', '-') + ".flv"), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None), null!);
public (Stream, object?) CreateOutputStream() => (File.Open(Path.Combine(TEST_OUTPUT_PATH, DateTimeOffset.Now.ToString("s").Replace(':', '-') + ".flv"), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None), null);
}
[Fact(Skip = "Not ready")]