Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# Stream

    private static void SplitFile(string inputFile, int chunkSize, string path)
    {
        byte[] buffer = new byte[chunkSize];
        List<byte> extraBuffer = new List<byte>();

        using (Stream input = File.OpenRead(inputFile))
        {
            int index = 0;
            while (input.Position < input.Length)
            {
                using (Stream output = File.Create(path + "" + index + ".csv"))
                {
                    int chunkBytesRead = 0;
                    while (chunkBytesRead < chunkSize)
                    {
                        int bytesRead = input.Read(buffer,
                                                   chunkBytesRead,
                                                   chunkSize - chunkBytesRead);

                        if (bytesRead == 0)
                        {
                            break;
                        }

                        chunkBytesRead += bytesRead;
                    }

                    byte extraByte = buffer[chunkSize - 1];
                    while (extraByte != '
')
                    {
                        int flag = input.ReadByte();
                        if (flag == -1)
                            break;
                        extraByte = (byte)flag;
                        extraBuffer.Add(extraByte);
                    }

                    output.Write(buffer, 0, chunkBytesRead);
                    if (extraBuffer.Count > 0)
                        output.Write(extraBuffer.ToArray(), 0, extraBuffer.Count);

                    extraBuffer.Clear();
                }
                index++;
            }
        }
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# loop backwards 
Csharp :: unity NetworkBehaviour the type or namespace could not be found 
Csharp :: unity in app review 
Csharp :: c# web scraping get images from specific url 
Csharp :: c# get folder of full ilepath 
Csharp :: unity find disabled gameobject 
Csharp :: how to get day name from datetimepicker in c# 
Csharp :: transform face player unity 
Csharp :: unity destroy gameobject with delay 
Csharp :: c# get regedit value 
Csharp :: unity error cs1656 
Csharp :: stackpanel opacity mask from resources wpf 
Csharp :: how crate cron netapp 
Csharp :: RadioButton IsChecked mapped to ENum xmal 
Html :: lodash cdn 
Html :: link css to html 
Html :: jquery ui cdn 
Html :: center text v-card 
Html :: html bootstrap textarea 
Html :: html open link in new tab 
Html :: taka html code 
Html :: adding a favicon in html 
Html :: conveert text to uppercase in input field 
Html :: font awesome reload icon 
Html :: html accept png and jpg 
Html :: link to send email with subject 
Html :: youtube iframe embed 
Html :: less than symbol html 
Html :: add link to text html 
Html :: ngfor index 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =