@@ -4,7 +4,7 @@ use crate::file::FileType;
4
4
use crate :: macros:: { decode_err, err, try_vec} ;
5
5
use crate :: ogg:: constants:: { OPUSTAGS , VORBIS_COMMENT_HEAD } ;
6
6
use crate :: ogg:: tag:: { create_vorbis_comments_ref, VorbisCommentsRef } ;
7
- use crate :: picture:: PictureInformation ;
7
+ use crate :: picture:: { Picture , PictureInformation } ;
8
8
use crate :: tag:: { Tag , TagType } ;
9
9
10
10
use std:: convert:: TryFrom ;
@@ -85,6 +85,30 @@ pub(crate) fn create_comments(
85
85
Ok ( ( ) )
86
86
}
87
87
88
+ fn create_pictures (
89
+ packet : & mut impl Write ,
90
+ count : & mut u32 ,
91
+ pictures : & mut dyn Iterator < Item = ( Picture , PictureInformation ) > ,
92
+ ) -> Result < ( ) > {
93
+ const PICTURE_KEY : & str = "METADATA_BLOCK_PICTURE=" ;
94
+
95
+ for ( pic, info) in pictures {
96
+ let picture = pic. as_flac_bytes ( info, true ) ;
97
+
98
+ let bytes_len = picture. len ( ) + PICTURE_KEY . len ( ) ;
99
+
100
+ if u32:: try_from ( bytes_len as u64 ) . is_ok ( ) {
101
+ * count += 1 ;
102
+
103
+ packet. write_u32 :: < LittleEndian > ( bytes_len as u32 ) ?;
104
+ packet. write_all ( PICTURE_KEY . as_bytes ( ) ) ?;
105
+ packet. write_all ( & picture) ?;
106
+ }
107
+ }
108
+
109
+ Ok ( ( ) )
110
+ }
111
+
88
112
pub ( super ) fn write < ' a , II , IP > (
89
113
file : & mut File ,
90
114
tag : & mut VorbisCommentsRef < ' a , II , IP > ,
@@ -93,7 +117,7 @@ pub(super) fn write<'a, II, IP>(
93
117
) -> Result < ( ) >
94
118
where
95
119
II : Iterator < Item = ( & ' a str , & ' a str ) > ,
96
- IP : Iterator < Item = ( & ' a crate :: picture :: Picture , PictureInformation ) > ,
120
+ IP : Iterator < Item = ( & ' a Picture , PictureInformation ) > ,
97
121
{
98
122
// TODO: Would be nice if we didn't have to read just to seek and reread immediately
99
123
@@ -163,7 +187,7 @@ pub(super) fn create_metadata_packet<'a, II, IP>(
163
187
) -> Result < Vec < u8 > >
164
188
where
165
189
II : Iterator < Item = ( & ' a str , & ' a str ) > ,
166
- IP : Iterator < Item = ( & ' a crate :: picture :: Picture , PictureInformation ) > ,
190
+ IP : Iterator < Item = ( & ' a Picture , PictureInformation ) > ,
167
191
{
168
192
const PICTURE_KEY : & str = "METADATA_BLOCK_PICTURE=" ;
169
193
@@ -179,20 +203,7 @@ where
179
203
180
204
let mut count = 0 ;
181
205
create_comments ( & mut new_comment_packet, & mut count, & mut tag. items ) ?;
182
-
183
- for ( pic, info) in & mut tag. pictures {
184
- let picture = pic. as_flac_bytes ( info, true ) ;
185
-
186
- let bytes_len = picture. len ( ) + PICTURE_KEY . len ( ) ;
187
-
188
- if u32:: try_from ( bytes_len as u64 ) . is_ok ( ) {
189
- count += 1 ;
190
-
191
- new_comment_packet. write_u32 :: < LittleEndian > ( bytes_len as u32 ) ?;
192
- new_comment_packet. write_all ( PICTURE_KEY . as_bytes ( ) ) ?;
193
- new_comment_packet. write_all ( & picture) ?;
194
- }
195
- }
206
+ create_pictures ( & mut new_comment_packet, & mut count, & mut tag. pictures ) ?;
196
207
197
208
// Seek back and write the item count
198
209
new_comment_packet. seek ( SeekFrom :: Start ( item_count_pos) ) ?;
0 commit comments