Adding `Span<byte>` / `Memory<byte>` API support to IStore

Đang mở
#12 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
backend-api-design, cloud

Hướng nghiên cứu

Start by reading the IStore API and the IBlobStorage implementations that currently accept byte[]; the issue does not name specific files or tests. Compare the proposed default interface method and extension method approaches, then determine how the API and implementations can accept Memory<byte> or Span<byte> while preserving existing callers. Done means the chosen API supports the requested buffer usage and the storage implementations are covered.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement major work in progress

Hi !
Is there any plan on adding support of Span<byte> / Memory<byte> where byte[] is currently required ?
(given that the introduction of these types help enhance memory usage and are spreading across the SDK)

Here a example where I think having overloads that accepts Span or Memory depending on the context could help

Memory<byte> buffer = GetBuffer();
Guid id = Guid.NewGuid();
string fileName = section.FileName;

string fullPath = $"upload/{id}";
Stream stream = section.Section.Body;
int bytesRead = 0;

// Streaming of the file
do
{
      bytesRead = await stream.ReadAsync(buffer.Memory, ct);
      await _storage.WriteAsync(fullPath, buffer.Memory.ToArray(), true, cancellationToken: ct);
 }
 while (bytesRead > 0);

which could be rewritten

Memory<byte> buffer = GetBuffer();
Guid id = Guid.NewGuid();
string fileName = section.FileName;

string fullPath = $"upload/{id}";
Stream stream = section.Section.Body;
int bytesRead = 0;

// Streaming of the file
do
{
      bytesRead = await stream.ReadAsync(buffer.Memory, ct);
      await _storage.WriteAsync(fullPath, buffer.Memory, true, cancellationToken: ct);
 }
 while (bytesRead > 0);

From what i've seen in the codebase, it would require to either :

  • go through all existing IBlobStorage implementations to add support for this but with a default interface implementation, the change could be as minimal as adding default method
Task WriteAsync(string fullPath, Memory<byte> data, bool append = false, CancellationToken cancellationToken = default) => WriteAsync(fullPath, new MemoryStream(data.ToArray()), append, cancellationToken);

This has the advantage of allowing implementors to provide a more memory efficient approach without breaking them (net6.0 upwards)

  • add a new IBlobStorage.WriteAsync extension method that would take a Memory<byte> instead of byte[]

Is that something that make sense to you ?

Ngôn ngữ chính
C#
Star
464
Fork
78
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của robinrodricks/FluentStorage

Tất cả issue của robinrodricks/FluentStorage

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.