'''
''' A class that wraps a file allowing you to serialize it for transport.
'''
_
Public Class WinsockFileData
#Region " Private Members "
Private _fileData() As Byte ' Stores the file data
Private _fileName As String ' Stores the file name
#End Region
#Region " Constructor "
'''
''' Initializes a new instance of the WinsockFileData class.
'''
Public Sub New()
_fileData = Nothing
_fileName = Nothing
End Sub
#End Region
#Region " Properties "
'''
''' Gets or sets the name of the file.
'''
Public Property FileName() As String
Get
Return _fileName
End Get
Set(ByVal value As String)
_fileName = value
End Set
End Property
'''
''' Gets or sets the contents of the file.
'''
Public Property FileData() As Byte()
Get
Return _fileData
End Get
Set(ByVal value As Byte())
_fileData = value
End Set
End Property
#End Region
#Region " Methods "
'''
''' Saves the file to the specified path.
'''
''' The full path of the file to save to.
''' Whether you want to append the data to the end of an existing file or not.
Public Sub SaveFile(ByVal save_path As String, Optional ByVal append As Boolean = False)
My.Computer.FileSystem.WriteAllBytes(save_path, _fileData, append)
End Sub
'''
''' Reads a file into the WinsockFileData class.
'''
''' The full path of the file you want to read.
Public Function ReadFile(ByVal file_path As String) As Boolean
Dim fi As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(file_path)
If fi.Exists Then
ReDim _fileData(0)
_fileName = fi.Name
_fileData = My.Computer.FileSystem.ReadAllBytes(fi.FullName)
Else
Return False
End If
Return True
End Function
#End Region
End Class