When copying sparse files using io.Copy(), they often inflate dramatically in size at the destination.
io.Copy() transfers raw bytes, which masks the presence of holes in a sparse file – the spaces where no data actually resides. This information is not accessible through standard syscalls like read(2). As such, io.Copy() is incapable of preserving the sparseness of files.
To address this, we need to delve deeper using the syscall package and manual handling. Lseek(2) system calls, with special SEEK_HOLE and SEEK_DATA values, can be used to manipulate holes in files.
If you want to maintain the sparseness of a file during transfer, the situation is more intricate. Fallocate(2) can be employed to attempt hole creation on supported filesystems. However, some filesystems inherently lack hole support, like the FAT family.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3