@@ -205,3 +205,57 @@ test('implicit torrent name from file names with slashes in them', t => {
205205 t . equal ( parsedTorrent . files [ 1 ] . path , path . join ( 'My Cool Folder' , 'My Cool File 2' ) )
206206 } )
207207} )
208+
209+ test ( 'verify torrent length with maxPieceLength set' , t => {
210+ t . plan ( 8 )
211+
212+ const buf1 = Buffer . from ( 'buf1' )
213+ buf1 . name = 'My Cool Folder/My Cool File 1'
214+
215+ const buf2 = Buffer . from ( 'buf2' )
216+ buf2 . name = 'My Cool Folder/My Cool File 2'
217+
218+ createTorrent ( [ buf1 , buf2 ] , { maxPieceLength : 10 } , async ( err , torrent ) => {
219+ t . error ( err )
220+ const parsedTorrent = await parseTorrent ( torrent )
221+
222+ t . equal ( parsedTorrent . name , 'My Cool Folder' )
223+
224+ t . equal ( parsedTorrent . files . length , 2 )
225+
226+ t . equal ( parsedTorrent . files [ 0 ] . name , 'My Cool File 1' )
227+ t . equal ( parsedTorrent . files [ 0 ] . path , path . join ( 'My Cool Folder' , 'My Cool File 1' ) )
228+
229+ t . equal ( parsedTorrent . files [ 1 ] . name , 'My Cool File 2' )
230+ t . equal ( parsedTorrent . files [ 1 ] . path , path . join ( 'My Cool Folder' , 'My Cool File 2' ) )
231+
232+ t . equal ( parsedTorrent . pieceLength , 10 )
233+ } )
234+ } )
235+
236+ test ( 'verify maxPieceLength is ignored when pieceLength is manually set' , t => {
237+ t . plan ( 8 )
238+
239+ const buf1 = Buffer . from ( 'buf1' )
240+ buf1 . name = 'My Cool Folder/My Cool File 1'
241+
242+ const buf2 = Buffer . from ( 'buf2' )
243+ buf2 . name = 'My Cool Folder/My Cool File 2'
244+
245+ createTorrent ( [ buf1 , buf2 ] , { pieceLength : 1024 , maxPieceLength : 10 } , async ( err , torrent ) => {
246+ t . error ( err )
247+ const parsedTorrent = await parseTorrent ( torrent )
248+
249+ t . equal ( parsedTorrent . name , 'My Cool Folder' )
250+
251+ t . equal ( parsedTorrent . files . length , 2 )
252+
253+ t . equal ( parsedTorrent . files [ 0 ] . name , 'My Cool File 1' )
254+ t . equal ( parsedTorrent . files [ 0 ] . path , path . join ( 'My Cool Folder' , 'My Cool File 1' ) )
255+
256+ t . equal ( parsedTorrent . files [ 1 ] . name , 'My Cool File 2' )
257+ t . equal ( parsedTorrent . files [ 1 ] . path , path . join ( 'My Cool Folder' , 'My Cool File 2' ) )
258+
259+ t . equal ( parsedTorrent . pieceLength , 1024 )
260+ } )
261+ } )
0 commit comments