在运行时设置缓冲区长度时,如何使用read(ubyte [] buffer)读取BufferedFile? [英] How do i read a BufferedFile using read(ubyte[] buffer) when the buffer length is set at runtime?
本文介绍了在运行时设置缓冲区长度时,如何使用read(ubyte [] buffer)读取BufferedFile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个二进制文件,实际上是文件的堆栈,格式为:
I have a binary file that is really a stack of files, the format is:
lengh_of_subfile,subfile
length_of_subfile
是64位整数。我可以读取 long
没问题,但是当我尝试为子文件创建缓冲区时,出现编译错误,提示无法在编译时读取。我想念什么?我用erlang,PHP和C#编写了一个相同的提取工具... D让我陷入循环。
length_of_subfile
is a 64-bit integer. I can read the long
no problem but when I try to create a buffer for the subfile I get compile errors saying it cannot be read at compile time. What am I missing? I've written an identical extraction tool in erlang, PHP and C#... D is throwing me for a loop.
void main(string args[]) {
Stream file = new BufferedFile(args[1], FileMode.In);
int counter = 0;
while(file.position < file.size) {
ulong len;
file.read(len);
ubyte[len] ogg;
file.read(ogg);
string outname = getcwd() ~ "/" ~ to!string(counter) ~ ".ogg";
Stream oggout = new BufferedFile(outname, FileMode.OutNew);
oggout.write(ogg);
writefln("Creating file " ~ to!string(counter) ~ ".ogg");
counter++;
}
}
推荐答案
ubyte[len] ogg;
写
ubyte[] ogg = new ubyte[len];
这篇关于在运行时设置缓冲区长度时,如何使用read(ubyte [] buffer)读取BufferedFile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文