BoomDAO / ICP.NET

A library for .NET/C#/Unity to natively communicate with the Internet Computer (ICP)
MIT License
50 stars 3 forks source link

AssetCanisterApiClient.UploadAssetChunkedAsync - file is not chunked correctly #123

Closed stefan-adna closed 5 months ago

stefan-adna commented 5 months ago

When using the AssetCanisterApiClient Class to upload files there is a problem when chunking the file.

int bytesRead = await contentStream.ReadAsync(buffer.AsMemory());
...
byte[] chunkBytes = bytesRead < buffer.Length
                ? buffer[0..(bytesRead - 1)]
                : buffer;

The upper bound of the array selector is exclusive, meaning reading 5 bytes should be buffer[0..5] which reads position 0-4 therefore the correct code should be buffer[0..(bytesRead - 1)] (without the -1).

Gekctek commented 5 months ago

Nice catch, ill fix

Gekctek commented 5 months ago

Fixed in 6.1.0

stefan-adna commented 4 months ago

Very nice. Looks good. Thanks a lot 👍