Mam plik binarny, który jest naprawdę stos plików, format jest:Jak mogę odczytać plik BufferedFile za pomocą read (bufora ubyte []), gdy długość bufora jest ustawiona w czasie wykonywania?
lengh_of_subfile,subfile
length_of_subfile
jest 64-bitową liczbą całkowitą. Mogę odczytać long
bez problemu, ale gdy próbuję utworzyć bufor dla fragmentu, otrzymuję błędy kompilacji mówiąc, że nie można go odczytać w czasie kompilacji. czego mi brakuje? Napisałem identyczne narzędzie do ekstrakcji w erlangu, PHP i C# ... D rzuca mnie na pętlę.
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++;
}
}
Potrzebujesz [tablica dynamiczna] (http: // stackoverflow.com/questions/8363728/d-dynamic-array-initialization-stride-and-tind-index-operation). (Nie mam pojęcia jak, bo nie programuję w D) – Ryan