简体   繁体   English

序列化分块文件

[英]Serializing a chunked file

I was following the example found here on serializing chunks of a large file. 我正在遵循此处找到的有关序列化大文件块的示例。 Somehow being new to serialization I am now lost as to what parameters to pass to my Serialize method. 不知何故是序列化的新手,现在我迷失了要传递给我的Serialize方法的参数。 I have shelved the approach I was using yesterday because of the OOM exception. 由于OOM异常,我搁置了昨天使用的方法。 Will appreciate your help. 将感谢您的帮助。

Public Shared Sub ReadAndProcessLargeFile(theFilename As String, ByVal obj As LocalDBObject, Optional whereToStartReading As Long = 0)
Dim bf As New BinaryFormatter() ' Create a binary formatter for this stream.

Using fileStram As New FileStream(theFilename, FileMode.Open, FileAccess.Read)
    Dim buffer As Byte() = New Byte(fileStram.Length - 1) {}
    fileStram.Seek(whereToStartReading, SeekOrigin.Begin)
    Dim bytesRead As Integer = fileStram.Read(buffer, 0, buffer.Length)
    While bytesRead > 0
        bytesRead = fileStram.Read(buffer, 0, buffer.Length - 1)
        'It is here where I am now lost. What parameters do I supply to my Serialize method below 
        bf.Serialize()
    End While
End Using
End Sub

Hmmm, that code is just not serializing anything, to serialize you should do this: 嗯,那个代码只是没有序列化任何东西,要序列化,您应该这样做:

Public Shared Sub Serialize(theFilename As String, ByVal obj As LocalDBObject)
    Dim bf As New BinaryFormatter() ' Create a binary formatter for this stream.

    Using fileStram As File.Create(theFilename)
        bf.Serialize(fileStram, obj);
    End Using
End Sub

But I suspect this is not what you want, unless you explain a bit better your question is really hard to understand what you want to achieve. 但是我怀疑这不是您想要的,除非您更好地解释您的问题,否则很难理解您想要实现的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM