io.SectionReader.Size() Function in Golang with Examples
Last Updated :
05 May, 2020
In Go language, io packages supply fundamental interfaces to the I/O primitives. And its principal job is to enclose the ongoing implementations of such king of primitives. The SectionReader.Size() function in Go language is used to find the size of the section that is returned by the NewSectionReader() method in bytes. Moreover, this function is defined under the io package. Here, you need to import the “io” package in order to use these functions.
Syntax:
func (s *SectionReader) Size() int64
Here, “s” is a pointer to the SectionReader which is returned by the NewSectionReader method.
Return value: It returns the size of the section returned in bytes and is of type int64.
Example 1:
package main
import (
"fmt"
"io"
"strings"
)
func main() {
reader := strings.NewReader( "Geeks" )
r := io.NewSectionReader(reader, 1, 4)
size := r.Size()
fmt.Printf( "The size of the section in bytes is: %v\n" , size)
}
|
Output:
The size of the section in bytes is: 4
Example 2:
package main
import (
"fmt"
"io"
"strings"
)
func main() {
reader := strings.NewReader( "GeeksforGeeks\nis\na\nCS-Portal.\n" )
r := io.NewSectionReader(reader, 5, 23)
size := r.Size()
fmt.Printf( "The size of the section in bytes is: %v\n" , size)
}
|
Output:
The size of the section in bytes is: 23
Share your thoughts in the comments
Please Login to comment...