Page 1 of 1
Reading a byte # from a file.
Posted: Fri Aug 07, 2009 11:59 am
by ConvertFromOldNGs
by Isaac Johnston >> Sun, 28 Jan 2001 4:22:32 GMT
Hey
Would anyone happen to know how to read from a certain byte within a file?? Eg For MP3 ID3 tags which always start 128 bytes from the end of the mp3. I have looked all though my Jade documentation and the help but have found nothing that would help.
Re: Reading a byte # from a file.
Posted: Fri Aug 07, 2009 11:59 am
by ConvertFromOldNGs
by Eric Peachey >> Sun, 28 Jan 2001 20:34:40 GMT
Hello Isaac,
On the File class there's a fileLength feature that tells you how big the file is. There is a seek method which positions the file pointer so that the next read starts from that point. Finally, there is the method readBinary to read as many bytes as needed (make sure the file's kind property is set to File.Kind_Binary.
This should provide you enough to do what you want, I think. The online help for the File class provides more info on these features (plus lots more).
Eric in Dunedin (sunny and warm)
Re: Reading a byte # from a file.
Posted: Fri Aug 07, 2009 11:59 am
by ConvertFromOldNGs
by Wilfred Verkley >> Mon, 29 Jan 2001 20:58:34 GMT
Jade can be a bit clumsy to do these kind of things though, becuase unlike other languages where you can just define a record structure for the entire ID3 tag, with Jade youve got to manually read or seperate each seperate field (title, artist, album etc).
i.e.
vars
f : File;
s : String;
title, artist, album, year, comment : String;
genre : Integer;begin
create f;
f.kind := File.Kind_Binary;
f.openInput ('brady-bunch-theme.mp3');
f.seek (f.fileLength - 128);
s := f.readBinary (128).String;
if s.length = 128 and s [1:3] = 'TAG' then
title := s [4:30];
artist := s [34:30];
album := s [64:30];
year := s [94:4];
comment := s [98:30];
genre := s [128:1].Character.Integer;
endif;
epilog
delete f;
end;