Seeking positions in a file

The Seek() function is useful for setting the file cursor in a specific location. By default, it starts at offset 0 and moves forward as you read bytes. You might want to reset the cursor back to the beginning of a file or jump directly to a specific location. The Seek() function allows you to do this.

Seek() takes two parameters. The first one is distance; you want to move the cursor in bytes. It can move forward with a positive integer, or backward in a file if a negative number is provided. The first parameter, the distance, is a relative value, not an absolute position in the file. The second parameter specifies where the relative point starts and is called whence. The whence parameter is the point of reference ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.