unify method for union the file read and write?
This commit is contained in:
parent
e8dfea6efd
commit
0bd2a98080
|
|
@ -955,6 +955,9 @@
|
|||
<Compile Include="ApplicationServices\VBDev\XmlDoc\Extensions\APIExtensions2.vb" />
|
||||
<Compile Include="ApplicationServices\VBDev\XmlDoc\Extensions\VBSpecific.vb" />
|
||||
<Compile Include="ApplicationServices\VBDev\XmlDoc\Serialization\NamespaceDoc.vb" />
|
||||
<Compile Include="CommandLine\CLI\Stream\Extensions.vb" />
|
||||
<Compile Include="CommandLine\CLI\Stream\StreamReader.vb" />
|
||||
<Compile Include="CommandLine\CLI\Stream\StreamWriter.vb" />
|
||||
<Compile Include="CommandLine\InteropService\InCompatible.vb" />
|
||||
<Compile Include="CommandLine\Interpreters\View\CommandHelp.vb" />
|
||||
<Compile Include="CommandLine\Reflection\RunDll.vb" />
|
||||
|
|
|
|||
|
|
@ -58,21 +58,21 @@ Imports System.IO.MemoryMappedFiles
|
|||
|
||||
Namespace Parallel.MMFProtocol.MapStream
|
||||
|
||||
Public MustInherit Class IMapBase : Implements IDisposable
|
||||
Public MustInherit Class MapStream : Implements IDisposable
|
||||
|
||||
Public ReadOnly Property URI As String
|
||||
|
||||
Protected _chunkBuffer As Byte()
|
||||
Protected _mmfileStream As MemoryMappedFile
|
||||
Protected buffer As Byte()
|
||||
Protected file As MemoryMappedFile
|
||||
|
||||
Sub New(uri As String, ChunkSize As Long)
|
||||
Sub New(uri As String, chunkSize As Integer)
|
||||
Me._URI = uri
|
||||
Me._chunkBuffer = New Byte(ChunkSize - 1) {}
|
||||
Me.buffer = New Byte(chunkSize - 1) {}
|
||||
End Sub
|
||||
|
||||
Public Function Read() As MMFStream
|
||||
Call _mmfileStream.CreateViewStream.Read(_chunkBuffer, Scan0, _chunkBuffer.Length)
|
||||
Return New MMFStream(_chunkBuffer)
|
||||
Call file.CreateViewStream.Read(buffer, Scan0, buffer.Length)
|
||||
Return New MMFStream(buffer)
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
|
|
@ -112,7 +112,7 @@ Namespace Parallel.MMFProtocol.MapStream
|
|||
#End Region
|
||||
End Class
|
||||
|
||||
Public Class MSIOReader : Inherits IMapBase
|
||||
Public Class MSIOReader : Inherits MapStream
|
||||
Implements IDisposable
|
||||
|
||||
''' <summary>
|
||||
|
|
@ -132,7 +132,7 @@ Namespace Parallel.MMFProtocol.MapStream
|
|||
''' <param name="ChunkSize">内存映射文件的数据块的预分配大小</param>
|
||||
Sub New(uri As String, callback As DataArrival, ChunkSize As Long)
|
||||
Call MyBase.New(uri, ChunkSize)
|
||||
_mmfileStream = MemoryMappedFile.OpenExisting(uri)
|
||||
file = MemoryMappedFile.OpenExisting(uri)
|
||||
_dataArrivals = callback
|
||||
|
||||
Call Parallel.RunTask(AddressOf __threadElapsed)
|
||||
|
|
@ -152,7 +152,7 @@ Namespace Parallel.MMFProtocol.MapStream
|
|||
''' <returns></returns>
|
||||
Public Function ReadBadge() As Long
|
||||
Dim buf As Byte() = New Byte(MMFStream.INT64 - 1) {}
|
||||
Call _mmfileStream.CreateViewStream.Read(buf, Scan0, buf.Length)
|
||||
Call file.CreateViewStream.Read(buf, Scan0, buf.Length)
|
||||
Dim n As Long = BitConverter.ToInt64(buf, Scan0)
|
||||
Return n
|
||||
End Function
|
||||
|
|
|
|||
|
|
@ -59,12 +59,12 @@ Namespace Parallel.MMFProtocol.MapStream
|
|||
#Region "Nested Type Definitions"
|
||||
|
||||
''' <summary>
|
||||
'''
|
||||
''' Memory stream writer
|
||||
''' </summary>
|
||||
''' <remarks>
|
||||
''' mmfServer的主要功能是创建并维护一个内存映射文件
|
||||
''' </remarks>
|
||||
Public Class MSWriter : Inherits IMapBase
|
||||
Public Class MSWriter : Inherits MapStream
|
||||
|
||||
''' <summary>
|
||||
'''
|
||||
|
|
@ -75,20 +75,16 @@ Namespace Parallel.MMFProtocol.MapStream
|
|||
Call MyBase.New(uri, chunkSize)
|
||||
|
||||
Try
|
||||
_mmfileStream =
|
||||
MemoryMappedFiles.MemoryMappedFile.CreateNew(
|
||||
uri, chunkSize)
|
||||
file = MemoryMappedFiles.MemoryMappedFile.CreateNew(uri, chunkSize)
|
||||
Catch ex As Exception
|
||||
_mmfileStream =
|
||||
MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(
|
||||
uri, chunkSize)
|
||||
file = MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(uri, chunkSize)
|
||||
Finally
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub WriteStream(byteData As Byte())
|
||||
If Not byteData.IsNullOrEmpty Then
|
||||
Call _mmfileStream.CreateViewStream.Write(
|
||||
Call file.CreateViewStream.Write(
|
||||
byteData, Scan0, byteData.Length)
|
||||
End If
|
||||
End Sub
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
Namespace CommandLine.Stream
|
||||
|
||||
<HideModuleName> Public Module Extensions
|
||||
|
||||
End Module
|
||||
End Namespace
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Namespace CommandLine.Stream
|
||||
|
||||
Public Class StreamReader
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Namespace CommandLine.Stream
|
||||
|
||||
Public Class StreamWriter
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
|
|
@ -64,7 +64,6 @@ Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic
|
|||
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
|
||||
Imports Microsoft.VisualBasic.Language
|
||||
Imports Microsoft.VisualBasic.Language.Default
|
||||
Imports Microsoft.VisualBasic.Language.UnixBash.FileSystem
|
||||
Imports Microsoft.VisualBasic.Linq
|
||||
Imports Microsoft.VisualBasic.Scripting
|
||||
Imports Microsoft.VisualBasic.Scripting.Expressions
|
||||
|
|
@ -73,6 +72,11 @@ Imports Microsoft.VisualBasic.Text
|
|||
|
||||
Namespace CommandLine
|
||||
|
||||
' file path: C://path/to/file
|
||||
' standard input: std_in://
|
||||
' standard output: std_out://
|
||||
' memory mapping file: memory://file/uri
|
||||
|
||||
''' <summary>
|
||||
''' A command line object that parse from the user input commandline string.
|
||||
''' (从用户所输入的命令行字符串之中解析出来的命令行对象,标准的命令行格式为:
|
||||
|
|
|
|||
Loading…
Reference in New Issue