Skip to content

Potential issue with SmbFileSystem.File.WriteAllBytes(filename, data); #7

@AMeyerInkSoft

Description

@AMeyerInkSoft

We were getting a sporadic error about "Not enough credits" when trying to write larger images to the fileshare. Troy's best guess is that the Windows Native SMB has better credit handling and scaling. Adam is unsure if the problem is Windows or Linux specific. It might be Windows-specific.

            // Old Logic: fs.File.WriteAllBytes(filename, data);
            // Open a stream instead of writing all bytes at once. Use 64 KB chunks for SMB efficiency
            const int chunkSize = 64 * 1024;
            using (var stream = fs.File.OpenWrite(filename))
            {
                int offset = 0;
                while (offset < data.Length)
                {
                    int bytesToWrite = Math.Min(chunkSize, data.Length - offset);
                    stream.Write(data, offset, bytesToWrite);
                    offset += bytesToWrite;
                }
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions