Runtime: API proposal: add IEnumerable<byte> overload to System.IO.File.WriteAllBytesAsync API

Created on 19 Jul 2019  路  2Comments  路  Source: dotnet/runtime

Greetings,

the current API for System.IO.WriteAllBytesAsync only supports byte[] as an input.

This prevents the usage of other buffer formats such as ImmutableArray<>.

It would be great if we had an additional overload with IEnumerable<byte> for both the Async and the Sync version of write all bytes, just as System.IO.WriteAllTextAsync does.

api-suggestion area-System.IO

Most helpful comment

I imagine one of the problems with that API would be that you'd need to still enumerate the bytes to write them in a block or write each byte individually and that would be slow.

Your best bet for ImmutableArray<byte> is probably ImmutableArray<byte>.AsMemory() and FileStream.WriteAsync(ReadOnlyMemory<Byte>, CancellationToken).

All 2 comments

I imagine one of the problems with that API would be that you'd need to still enumerate the bytes to write them in a block or write each byte individually and that would be slow.

Your best bet for ImmutableArray<byte> is probably ImmutableArray<byte>.AsMemory() and FileStream.WriteAsync(ReadOnlyMemory<Byte>, CancellationToken).

This question has been answered, so I'm closing the issue. If you feel this has been closed incorrectly then please reopen and add more info. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EgorBo picture EgorBo  路  3Comments

bencz picture bencz  路  3Comments

matty-hall picture matty-hall  路  3Comments

jamesqo picture jamesqo  路  3Comments

v0l picture v0l  路  3Comments