-
Joe Tsai authored
To support the detection and creation of sparse files, add two new methods: func Header.DetectSparseHoles(*os.File) error func Header.PunchSparseHoles(*os.File) error DetectSparseHoles is intended to be used after FileInfoHeader prior to serializing the Header with WriteHeader. For each OS, it uses specialized logic to detect the location of sparse holes. On most Unix systems, it uses SEEK_HOLE and SEEK_DATA to query for the holes. On Windows, it uses a specialized the FSCTL_QUERY_ALLOCATED_RANGES syscall to query for all the holes. PunchSparseHoles is intended to be used after Reader.Next prior to populating the file with Reader.WriteTo. On Windows, this uses the FSCTL_SET_ZERO_DATA syscall. On other operating systems it simply truncates the file to the end-offset of SparseHoles. DetectSparseHoles and PunchSparseHoles are added as methods on Header because they are heavily tied to the operating system, for which there is already an existing precedence for (since FileInfoHeader makes uses of OS-specific details). Fixes #13548 Change-Id: I98a321dd1ce0165f3d143d4edadfda5e7db67746 Reviewed-on: https://go-review.googlesource.com/60871 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1eacf788