Forest_Client/Forest/Assets/PhxhSDK/AOT/YooAsset/CustomFileStream.cs

104 lines
2.2 KiB
C#

using System.IO;
using UnityEngine;
namespace PhxhSDK.AOT
{
public class CustomFileStream : Stream
{
private FileStream _fileStream;
public CustomFileStream(string path)
{
_fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
}
public override void Flush()
{
Debug.LogError("不支持Flush操作");
}
public override int Read(byte[] buffer,
int offset,
int count)
{
var read = _fileStream.Read(buffer, offset, count);
for (int i = 0; i < read; i++)
{
// 取反
var index = offset + i;
buffer[index] = (byte)~buffer[index];
}
return read;
}
public override long Seek(long offset,
SeekOrigin origin)
{
return _fileStream.Seek(offset, origin);
}
public override void SetLength(long value)
{
_fileStream.SetLength(value);
}
public override void Write(byte[] buffer,
int offset,
int count)
{
Debug.LogError("不支持Write操作");
}
public override bool CanRead
{
get
{
return _fileStream.CanRead;
}
}
public override bool CanSeek
{
get
{
return _fileStream.CanSeek;
}
}
public override bool CanWrite
{
get
{
return false;
}
}
public override long Length
{
get
{
return _fileStream.Length;
}
}
public override long Position
{
get
{
return _fileStream.Position;
}
set
{
_fileStream.Position = value;
}
}
public override void Close()
{
base.Close();
_fileStream.Close();
}
}
}