Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ac44e8a

Browse files
committed
add FileSystem.OpenRead
1 parent f684953 commit ac44e8a

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

Assets/UnityFS/AbstractFileSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ protected void OnLoaded()
5858
public abstract bool Exists(string filename);
5959

6060
public abstract byte[] ReadAllBytes(string filename);
61+
62+
public abstract Stream OpenRead(string filename);
6163
}
6264
}

Assets/UnityFS/BundleAssetProvider.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public override byte[] ReadAllBytes(string filename)
5151
{
5252
return _bundle.ReadAllBytes(filename);
5353
}
54+
55+
public override Stream OpenRead(string filename)
56+
{
57+
return _bundle.OpenRead(filename);
58+
}
5459
}
5560

5661
public class ZipArchiveUBundle : UBundle
@@ -88,6 +93,20 @@ public bool Exists(string filename)
8893
return false;
8994
}
9095

96+
// 打开压缩包中的文件, 返回其文件流
97+
public Stream OpenRead(string filename)
98+
{
99+
if (_zipFile != null)
100+
{
101+
var entry = _zipFile.GetEntry(filename);
102+
if (entry != null)
103+
{
104+
return _zipFile.GetInputStream(entry);
105+
}
106+
}
107+
return null;
108+
}
109+
91110
public byte[] ReadAllBytes(string filename)
92111
{
93112
if (_zipFile != null)

Assets/UnityFS/FailureFileSystem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@ public byte[] ReadAllBytes(string filename)
4141
{
4242
return null;
4343
}
44+
45+
public Stream OpenRead(string filename)
46+
{
47+
return null;
48+
}
4449
}
4550
}

Assets/UnityFS/FileSystem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface IFileSystem
1111
event Action<IFileSystem> completed; // 加载完成
1212

1313
bool Exists(string filename);
14+
Stream OpenRead(string filename);
1415
byte[] ReadAllBytes(string filename);
1516
}
1617
}

Assets/UnityFS/OrdinaryFileSystem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public override bool Exists(string filename)
2525
return File.Exists(Path.Combine(_rootPath, filename));
2626
}
2727

28+
public override Stream OpenRead(string filename)
29+
{
30+
if (string.IsNullOrEmpty(_rootPath))
31+
{
32+
return File.OpenRead(filename);
33+
}
34+
return File.OpenRead(Path.Combine(_rootPath, filename));
35+
}
36+
2837
public override byte[] ReadAllBytes(string filename)
2938
{
3039
if (string.IsNullOrEmpty(_rootPath))

0 commit comments

Comments
 (0)