edjCase / ICP.NET

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

AssetCanisterApiClient.UploadAssetChunkedAsync - file is not chunked correctly #123

Closed stefan-adna closed 7 months ago

stefan-adna commented 7 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 7 months ago

Nice catch, ill fix

Gekctek commented 7 months ago

Fixed in 6.1.0

stefan-adna commented 7 months ago

Very nice. Looks good. Thanks a lot 👍