File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
LuYao.ResourcePacker.Tests Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,12 @@ public class ResourcePackageReaderThreadSafetyTests : IDisposable
1515
1616 public ResourcePackageReaderThreadSafetyTests ( )
1717 {
18- // 创建临时目录用于测试
18+ // Create temporary directory for tests
1919 _tempDirectory = Path . Combine ( Path . GetTempPath ( ) , $ "ResourcePackerThreadSafetyTests_{ Guid . NewGuid ( ) } ") ;
2020 Directory . CreateDirectory ( _tempDirectory ) ;
2121 _outputPath = Path . Combine ( _tempDirectory , "test.dat" ) ;
2222
23- // 创建测试资源包
23+ // Create test resource package
2424 var sourceDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , "TestResources" ) ;
2525 var packer = new ResourcePacker ( sourceDir , "*.res.*" ) ;
2626 packer . PackResources ( _outputPath ) ;
@@ -231,7 +231,7 @@ public void ConcurrentStreamReads_ShouldNotCorruptData()
231231
232232 public void Dispose ( )
233233 {
234- // 清理临时目录
234+ // Clean up temporary directory
235235 if ( Directory . Exists ( _tempDirectory ) )
236236 {
237237 Directory . Delete ( _tempDirectory , true ) ;
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public bool ContainsKey(string resourceKey)
8484 /// </summary>
8585 /// <param name="resourceKey">The key of the resource to read.</param>
8686 /// <returns>A task that represents the asynchronous read operation.</returns>
87- public async Task < byte [ ] > ReadResourceAsync ( string resourceKey )
87+ public Task < byte [ ] > ReadResourceAsync ( string resourceKey )
8888 {
8989 if ( _disposed )
9090 throw new ObjectDisposedException ( nameof ( ResourcePackageReader ) ) ;
@@ -98,10 +98,18 @@ public async Task<byte[]> ReadResourceAsync(string resourceKey)
9898 lock ( _lock )
9999 {
100100 _fileStream . Seek ( entry . Offset , SeekOrigin . Begin ) ;
101- _fileStream . Read ( buffer , 0 , buffer . Length ) ;
101+
102+ int totalRead = 0 ;
103+ while ( totalRead < entry . Length )
104+ {
105+ int bytesRead = _fileStream . Read ( buffer , totalRead , entry . Length - totalRead ) ;
106+ if ( bytesRead == 0 )
107+ throw new EndOfStreamException ( $ "Unexpected end of stream while reading resource '{ resourceKey } '.") ;
108+ totalRead += bytesRead ;
109+ }
102110 }
103111
104- return await Task . FromResult ( buffer ) ;
112+ return Task . FromResult ( buffer ) ;
105113 }
106114
107115 /// <summary>
You can’t perform that action at this time.
0 commit comments