@@ -30,6 +30,15 @@ impl OGGFormat {
3030 OGGFormat :: Speex => None ,
3131 }
3232 }
33+
34+ pub ( super ) fn from_filetype ( file_type : FileType ) -> ( Self , isize ) {
35+ match file_type {
36+ FileType :: Opus => ( OGGFormat :: Opus , 2 ) ,
37+ FileType :: Vorbis => ( OGGFormat :: Vorbis , 3 ) ,
38+ FileType :: Speex => ( OGGFormat :: Speex , 2 ) ,
39+ _ => unreachable ! ( "You forgot to add support for FileType::{:?}!" , file_type) ,
40+ }
41+ }
3342}
3443
3544pub ( crate ) fn write_to ( file : & mut File , tag : & Tag , file_type : FileType ) -> Result < ( ) > {
@@ -45,14 +54,9 @@ pub(crate) fn write_to(file: &mut File, tag: &Tag, file_type: FileType) -> Resul
4554 pictures,
4655 } ;
4756
48- let format = match file_type {
49- FileType :: Opus => OGGFormat :: Opus ,
50- FileType :: Vorbis => OGGFormat :: Vorbis ,
51- FileType :: Speex => OGGFormat :: Speex ,
52- _ => unreachable ! ( ) ,
53- } ;
57+ let ( format, header_packet_count) = OGGFormat :: from_filetype ( file_type) ;
5458
55- write ( file, & mut comments_ref, format)
59+ write ( file, & mut comments_ref, format, header_packet_count )
5660}
5761
5862pub ( crate ) fn create_comments (
@@ -85,6 +89,7 @@ pub(super) fn write<'a, II, IP>(
8589 file : & mut File ,
8690 tag : & mut VorbisCommentsRef < ' a , II , IP > ,
8791 format : OGGFormat ,
92+ header_packet_count : isize ,
8893) -> Result < ( ) >
8994where
9095 II : Iterator < Item = ( & ' a str , & ' a str ) > ,
99104 let stream_serial = first_page_header. stream_serial ;
100105
101106 file. seek ( SeekFrom :: Start ( start) ) ?;
102- let mut packets = Packets :: read_count ( file, 3 ) ?;
107+ let mut packets = Packets :: read_count ( file, header_packet_count ) ?;
103108
104109 let mut remaining_file_content = Vec :: new ( ) ;
105110 file. read_to_end ( & mut remaining_file_content) ?;
0 commit comments