繁体   English   中英

使用BinaryWriter进行部分文件更新

[英]Using a BinaryWriter for partial file updates

我正在寻找一种可以进行部分更新的方法,可以使用BinaryWriter从字典中添加键/值对并将其删除。 使用下面的代码覆盖一个完整的文件似乎很简单,但是由于我可能有很多记录(约26,000个),因此我担心性能会成为问题。 (我尚未运行测试来确认这一点)。

我需要的上下文是通过HttpModule访问的缓存图像文件的持久索引。

我的出发点:

using (FileStream fileStream = File.Create(this.cachedIndexFile))
{
    using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
    {
        // Put the count.
        binaryWriter.Write(this.Count);

        // Put the values.
        foreach (var pair in this)
        {
            binaryWriter.Write(pair.Key);
            binaryWriter.Write(pair.Value.ToString());
        }
    }
}

如果框架内有更好的选择,我会很乐意使用它们。 BinaryWriter是我唯一了解的事情,并且搜索替代品已证明是毫无用处的。

我在这里找到了这篇文章但发现很难理解,并且下载可下载的项目文件更加困难。 也许可以基于此解决方案?

遵循注释中的建议,我认为确实最好的数据库是数据库。 我已经使用SQLite。

暂无
暂无

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

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