public class FileSplitter : IDisposable
Public Class FileSplitter
Implements IDisposable
Dim instance As FileSplitter
public ref class FileSplitter : IDisposable
type FileSplitter =
class
interface IDisposable
end
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Imports System.IO
Public Class Form1 : Inherits Form
Friend WithEvents Splitter As New FileSplitter("C:\File.ext") With {.BufferSize = .BufferSize}
Friend WithEvents Merger As FileSplitter
' Splitter settings.
Private ReadOnly chunkName As String = "File.Part"
Private ReadOnly chunkExt As String = "fs"
' Some default chunk sizes to split a file.
Private ReadOnly kilobyte As Integer = 1024
Private ReadOnly megabyte As Integer = 1048576
Private ReadOnly gigabyte As Integer = 1073741824
Private ReadOnly halfFileSize As Long = CLng(Me.Splitter.File.Length / 2)
' The label controls that will display the progress.
Friend LabelSplit1 As New Label, LabelSplit2 As New Label, LabelSplit3 As New Label
Friend LabelMerge1 As New Label, LabelMerge2 As New Label, LabelMerge3 As New Label
' The button controls to start a split or merge operation.
Friend WithEvents ButtonSplit As New Button, ButtonMerge As New Button
Public Sub New()
' This call is required by the designer.
Me.InitializeComponent()
' Set the controls properties.
With Me.ButtonSplit
.Text = "Split"
.Font = New Font(Me.Font.FontFamily, 14.0F, FontStyle.Bold)
.Size = New Size(200, 75)
.Location = New Point(0, 0)
.Cursor = Cursors.Hand
End With
With Me.ButtonMerge
.Text = "Merge"
.Font = New Font(Me.Font.FontFamily, 14.0F, FontStyle.Bold)
.Size = New Size(200, 75)
.Location = New Point(Me.ButtonSplit.Location.X + Me.ButtonSplit.Width, 0)
.Cursor = Cursors.Hand
End With
With Me.LabelSplit1
.Text = "Total Progress:"
.AutoSize = True
.Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
.Location = New Point(0, Me.ButtonSplit.Location.Y + Me.ButtonSplit.Height + 10)
End With
With Me.LabelSplit2
.Text = "Chunk Progress:"
.AutoSize = True
.Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
.Location = New Point(0, Me.LabelSplit1.Location.Y + Me.LabelSplit1.Height)
End With
With Me.LabelSplit3
.Text = "Chunk Count:"
.AutoSize = True
.Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
.Location = New Point(0, Me.LabelSplit2.Location.Y + Me.LabelSplit2.Height)
End With
With Me.LabelMerge1
.Text = "Total Progress:"
.AutoSize = True
.Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
.Location = New Point(Me.ButtonMerge.Location.X, Me.ButtonMerge.Location.Y + Me.ButtonMerge.Height + 10)
End With
With Me.LabelMerge2
.Text = "Chunk Progress:"
.AutoSize = True
.Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
.Location = New Point(Me.ButtonMerge.Location.X, Me.LabelMerge1.Location.Y + Me.LabelMerge1.Height)
End With
With Me.LabelMerge3
.Text = "Chunk Count:"
.AutoSize = True
.Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
.Location = New Point(Me.ButtonMerge.Location.X, Me.LabelMerge2.Location.Y + Me.LabelMerge2.Height)
End With
' Add the controls on the UI.
Me.Controls.AddRange({Me.LabelSplit1, Me.LabelSplit2, Me.LabelSplit3,
Me.LabelMerge1, Me.LabelMerge2, Me.LabelMerge3,
Me.ButtonSplit, Me.ButtonMerge})
' Set the Form properties.
With Me
.Size = New Size(Me.ButtonSplit.Width + Me.ButtonMerge.Width + 20, 200)
.FormBorderStyle = FormBorderStyle.FixedDialog
.MaximizeBox = False
End With
End Sub
Private Sub ButtonSplit_Click() Handles ButtonSplit.Click
Me.ButtonSplit.Enabled = False
Me.Splitter.Split(chunkSize:=Me.halfFileSize,
chunkName:=Me.chunkName,
chunkExt:=Me.chunkExt,
overwrite:=True,
deleteAfterSplit:=False)
' Or...
'Me.splitter.Split(chunkCount:=2,
' chunkName:=Me.chunkName,
' chunkExt:=Me.chunkExt,
' overwrite:=True,
' deleteAfterSplit:=False)
End Sub
''' <summary>
''' Handles the <see cref="Button.Click"/> event of the <see cref="ButtonMerge"/> control.
''' </summary>
Private Sub ButtonMerge_Click() Handles ButtonMerge.Click
Me.ButtonMerge.Enabled = False
Me.Merger = New FileSplitter("C:\File.Part.1.fs") With {.BufferSize = .BufferSize}
Dim targetFileName As String = String.Format("{0}{1}{2}", Me.Merger.File.DirectoryName, "Merged", Me.Merger.File.Extension)
Me.Merger.Merge(targetFile:=targetFileName,
overwrite:=True,
deleteChunksAfterMerged:=False)
End Sub
''' <summary>
''' Handles the <see cref="FileSplitter.ProgressChanged"/> event of the <see cref="Splitter"/> instance.
''' </summary>
''' <param name="sender">
''' The source of the event.
''' </param>
''' <param name="e">
''' The <see cref="FileSplitterProgressChangedEventArgs"/> instance containing the event data.
''' </param>
Private Sub Splitter_ProgressChanged(ByVal sender As Object, ByVal e As FileSplitterProgressChangedEventArgs) _
Handles Splitter.ProgressChanged
Me.LabelSplit1.Text = String.Format("Total Progress: {0}%", e.TotalProgress.ToString("n1"))
Me.LabelSplit2.Text = String.Format("Chunk Progress: {0}%", e.ChunkProgress.ToString("n1"))
Me.LabelSplit3.Text = String.Format("Current Chunk: {0} of {1}", CStr(e.ChunksCreatedOrMerged + 1), CStr(e.ChunksToCreateOrMerge))
Application.DoEvents()
If (e.TotalProgress = 100.0R) Then
Me.ButtonSplit.Enabled = True
End If
End Sub
''' <summary>
''' Handles the <see cref="FileSplitter.ProgressChanged"/> event of the <see cref="Merger"/> instance.
''' </summary>
''' <param name="sender">
''' The source of the event.
''' </param>
''' <param name="e">
''' The <see cref="FileSplitterProgressChangedEventArgs"/> instance containing the event data.
''' </param>
Private Sub Merger_ProgressChanged(ByVal sender As Object, ByVal e As FileSplitterProgressChangedEventArgs) _
Handles Merger.ProgressChanged
Me.LabelMerge1.Text = String.Format("Total Progress: {0}%", e.TotalProgress.ToString("n1"))
Me.LabelMerge2.Text = String.Format("Chunk Progress: {0}%", e.ChunkProgress.ToString("n1"))
Me.LabelMerge3.Text = String.Format("Current Chunk: {0} of {1}", CStr(e.ChunksCreatedOrMerged + 1), CStr(e.ChunksToCreateOrMerge))
Application.DoEvents()
If (e.TotalProgress = 100.0R) Then
Me.ButtonMerge.Enabled = True
End If
End Sub
End Class
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
FileSplitter | Initializes a new instance of the FileSplitter class. |
BufferSize | Gets or sets the buffer size used to split or merge, in Bytes. Default value is: Kb128. |
File | Gets the file to split or merge. |
Dispose | Releases all the resources used by this instance. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
Merge | Merges the chunks of a previously splitted file. |
Split(Int32, String, String, Boolean, Boolean) | Splits a file into the specified amount of chunks. |
Split(Int64, String, String, Boolean, Boolean) | Splits a file into chunks of the specified filesize. |
ToString | Returns a string that represents the current object. (Inherited from Object) |
ProgressChanged | Occurs when the progress changes when splitting or merging a file. |
CanConvertTo |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
CanConvertToT |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, an exception is thrown.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, returns the specified default value.
(Defined by ObjectExtensions) |
IsDisposable |
Determines whether the specified object is a disposable type
(i.e., it implements IDisposable interface).
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
ThrowIfNullTException |
Throws the specified exception if the source object is null.
(Defined by ObjectExtensions) |