Get size of a file before downloading in Python

前端 未结 8 1287
名媛妹妹
名媛妹妹 2020-12-02 06:56

I\'m downloading an entire directory from a web server. It works OK, but I can\'t figure how to get the file size before download to compare if it was updated on the server

8条回答
  •  旧巷少年郎
    2020-12-02 07:16

    @PabloG Regarding the local/server filesize difference

    Following is high-level illustrative explanation of why it may occur:

    The size on disk sometimes is different from the actual size of the data. It depends on the underlying file-system and how it operates on data. As you may have seen in Windows when formatting a flash drive you are asked to provice 'block/cluster size' and it varies [512b - 8kb]. When a file is written on the disk, it is storled in a 'sort-of linked list' of disk blocks. When a certain block is used to store part of a file, no other file contents will be stored in the same blok, so even if the chunk is no occupuing the entire block space, the block is rendered unusable by other files.

    Example: When the filesystem is divided on 512b blocks, and we need to store 600b file, two blocks will be occupied. The first block will be fully utilized, while the second block will have only 88b utilized and the remaining (512-88)b will be unusable resulting in 'file-size-on-disk' being 1024b. This is why Windows has different notations for 'file size' and 'size on disk'.

    NOTE: There are different pros & cons that come with smaller/bigger FS block, so do a better research before playing with your filesystem.

提交回复
热议问题