nika-begiashvili / libarchivejs

Archive library for browsers
MIT License
288 stars 35 forks source link

Unsorted files on rar archives #22

Closed btzr-io closed 4 years ago

btzr-io commented 4 years ago

getFilesArray() is returning unsorted items for some rar archives. Example archive: https://github.com/workhorsy/uncompress.js/blob/master/example_rar_5.rar

Any ideas why ?

nika-begiashvili commented 4 years ago

I believe libarchive is returning files "as is" written inside file, meaning order is specific to however archive was created, do you have any reason to think it might not be that case ?

btzr-io commented 4 years ago

Got the same result with: https://wcchoi.github.io/libunrar-js/

btzr-io commented 4 years ago

Just in case someone has the same problem:

    // Get files list
    const files = await archive.current.getFilesArray()

    // Sort files by name
    files.sort((a, b) => {
        if (a.file.name > b.file.name) return 1
        if (a.file.name < b.file.name) return -1
        return 0
     })