{"id":475,"date":"2026-06-07T09:00:00","date_gmt":"2026-06-07T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/"},"modified":"2026-06-07T09:00:00","modified_gmt":"2026-06-07T03:30:00","slug":"go-io-reader-writer","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/","title":{"rendered":"Go Reader and Writer Interfaces Explained Simply"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Go Reader and Writer interfaces are two tiny interfaces that move data between files, networks, strings and more. In this post, you will learn how <code>io.Reader<\/code> and <code>io.Writer<\/code> work and why almost every Go program uses them. Then we will build a custom reader and writer and test six useful helpers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-interfaces-examples\/\">Go interfaces<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-file-handling-examples\/\">Go file handling<\/a>. We also use ideas from <a href=\"https:\/\/smitabharat.com\/blog\/go-methods-receivers\/\">Go methods and receivers<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-examples\/\">Go strings<\/a>. So it helps to read those first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Reader and Writer Interfaces?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A reader is anything you can read bytes from. Likewise, a writer is anything you can write bytes to. In Go, each idea is an interface with exactly one method. The <code>io.Reader<\/code> interface has <code>Read<\/code>, and the <code>io.Writer<\/code> interface has <code>Write<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of water pipes. A tap is a source, while a bucket is a place to store water. You can join any tap to any bucket with a pipe, as long as the ends fit. In the same way, the Go Reader and Writer interfaces are the ends that fit. A file, a network connection, a string and a buffer can all join together, since they share the same ends.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the interfaces are so small, hundreds of types in the standard library satisfy them. Besides, they are easy to remember. As a result, a function that accepts an <code>io.Reader<\/code> works with all of them without any change. This is the main strength of the Go Reader and Writer interfaces.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Reader and Writer Interfaces Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Without a shared idea, every source would need its own code. For instance, you would write one function for files, one for network data and one for strings. Here is what the Go Reader and Writer interfaces give you.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Reuse<\/strong>: one function works with files, sockets, buffers and strings.<\/li>\n\n\n\n<li><strong>Streaming<\/strong>: you handle data piece by piece, so memory use stays low.<\/li>\n\n\n\n<li><strong>Easy testing<\/strong>: you can test with a string instead of a real file.<\/li>\n\n\n\n<li><strong>Composition<\/strong>: small tools snap together like building blocks.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Also, many packages follow the same style. For example, the <code>json<\/code> package decodes from any reader, and <code>fmt.Fprintf<\/code> prints to any writer. Therefore, learning the Go Reader and Writer interfaces opens up a large part of the standard library.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Reader and Writer Interfaces Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both signatures are short. <code>Read(p []byte) (n int, err error)<\/code> fills your slice with up to <code>len(p)<\/code> bytes and says how many it wrote. Likewise, <code>Write(p []byte) (n int, err error)<\/code> takes your bytes and says how many it accepted.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1-1024x640.png\" alt=\"Go Reader and Writer diagram showing files, strings and connections feeding io.Copy and three writers receiving data\" class=\"wp-image-451\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A Reader supplies bytes, a Writer receives them, and io.Copy moves data from one to the other in small chunks. Files, strings and network connections all fit either end.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">How Read Signals the End<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A reader tells you it has no more data by returning the special error <code>io.EOF<\/code>. This is not a real failure, because it is just the end marker. Helper functions such as <code>io.ReadAll<\/code> and <code>io.Copy<\/code> handle it for you. So you rarely see it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why Streaming Saves Memory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you copy a 2 GB file. When you load it all into memory first, you need 2 GB of RAM. With <code>io.Copy<\/code>, Go reads a small chunk, writes it and then repeats. So the memory use stays tiny, even for huge files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Types That Already Satisfy Reader and Writer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You rarely need to write your own types, because the standard library already has many. The table below shows common ones.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Type<\/th><th>Reader<\/th><th>Writer<\/th><th>Typical use<\/th><\/tr><\/thead><tbody><tr><td>os.File<\/td><td>Yes<\/td><td>Yes<\/td><td>Files on disk<\/td><\/tr><tr><td>strings.Reader<\/td><td>Yes<\/td><td>No<\/td><td>Tests and small text<\/td><\/tr><tr><td>bytes.Buffer<\/td><td>Yes<\/td><td>Yes<\/td><td>Build or collect bytes in memory<\/td><\/tr><tr><td>net.Conn<\/td><td>Yes<\/td><td>Yes<\/td><td>Network connections<\/td><\/tr><tr><td>http.Request body<\/td><td>Yes<\/td><td>No<\/td><td>Data sent by a client<\/td><\/tr><tr><td>http.ResponseWriter<\/td><td>No<\/td><td>Yes<\/td><td>Data sent to a client<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that <code>http.ResponseWriter<\/code> is a writer. Because of that, you can pass it straight to <code>fmt.Fprintf<\/code> or <code>json.NewEncoder<\/code>. Similarly, a request body is a reader, so you can hand it to <code>json.NewDecoder<\/code>. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\">Go JSON guide<\/a> uses exactly this style.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Buffering for Speed<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reading one byte at a time from a file is slow, because each call asks the system for data. The <code>bufio<\/code> package solves this. It wraps a reader with a buffer. Then the system is asked for a large block only once in a while. In the same way, <code>bufio.Writer<\/code> batches small writes. Remember to call <code>Flush<\/code> at the end, or the last bytes may never leave the buffer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Reader and Writer: Helpers at a Glance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>io<\/code> package ships helpers that build on the two interfaces. The table below lists the ones we use in this lesson.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Helper<\/th><th>What it does<\/th><th>Typical use<\/th><\/tr><\/thead><tbody><tr><td>io.Copy<\/td><td>Moves all data from a reader to a writer<\/td><td>Copy a file or a response<\/td><\/tr><tr><td>io.ReadAll<\/td><td>Reads everything into memory<\/td><td>Small bodies and tests<\/td><\/tr><tr><td>io.LimitReader<\/td><td>Stops after N bytes<\/td><td>Protect against huge uploads<\/td><\/tr><tr><td>io.TeeReader<\/td><td>Copies what is read into a writer<\/td><td>Log or hash while reading<\/td><\/tr><tr><td>io.MultiWriter<\/td><td>Sends one write to many writers<\/td><td>Log to screen and file<\/td><\/tr><tr><td>bufio.Scanner<\/td><td>Reads line by line<\/td><td>Text files and input<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2-1024x640.png\" alt=\"Go Reader and Writer diagram showing a reader wrapped by LimitReader and upperReader and copied to a MultiWriter\" class=\"wp-image-452\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Wrapping readers and writers: a LimitReader wraps a source, a custom upper-case reader wraps another reader, and a MultiWriter fans one write out to three places.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">These helpers all return or accept readers and writers. For that reason, you can stack them like blocks. For example, you can limit a reader, then tee it into a hash and finally copy it to a file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Reader and Writer Hands-On: Six Examples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s write the code. First we make two small types of our own, and then we use the helpers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Your Own Reader and Writer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>upperReader<\/code> wraps another reader. Its <code>Read<\/code> method calls the inner reader and upper-cases the bytes that came back. Next, <code>countWriter<\/code> counts the bytes written through it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type upperReader struct{ r io.Reader }\n\nfunc (u upperReader) Read(p []byte) (int, error) {\n\tn, err := u.r.Read(p)\n\tcopy(p, bytes.ToUpper(p[:n]))\n\treturn n, err\n}\n\ntype countWriter struct{ n int }\n\nfunc (c *countWriter) Write(p []byte) (int, error) {\n\tc.n += len(p)\n\treturn len(p), nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at the key lines. In <code>upperReader<\/code>, we only touch the first <code>n<\/code> bytes, because the rest of the slice holds old data. We also return <code>err<\/code> as it is, so that <code>io.EOF<\/code> passes through. In <code>countWriter<\/code>, we use a pointer receiver, because the counter must keep growing between calls.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Use Them with the Helpers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Then <code>main<\/code> tries six ideas one after another. We print a short line after each step, so the output is easy to read.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\tsrc := strings.NewReader(\"hello from a string\\n\")\n\tn, _ := io.Copy(os.Stdout, src)\n\tfmt.Println(\"copied bytes:\", n)\n\n\tio.Copy(os.Stdout, upperReader{strings.NewReader(\"quiet text\\n\")})\n\n\tsc := bufio.NewScanner(strings.NewReader(\"line one\\nline two\\nline three\"))\n\tfor sc.Scan() {\n\t\tfmt.Println(\"scanned:\", sc.Text())\n\t}\n\n\tvar buf bytes.Buffer\n\tcw := &amp;countWriter{}\n\tmw := io.MultiWriter(&amp;buf, cw, os.Stdout)\n\tfmt.Fprintln(mw, \"logged twice\")\n\tfmt.Printf(\"buffer=%q counted=%d\\n\", buf.String(), cw.n)\n\n\tlim := io.LimitReader(strings.NewReader(\"0123456789\"), 4)\n\tb, _ := io.ReadAll(lim)\n\tfmt.Println(\"limited:\", string(b))\n\n\tvar seen bytes.Buffer\n\ttee := io.TeeReader(strings.NewReader(\"tee data\"), &amp;seen)\n\tio.ReadAll(tee)\n\tfmt.Println(\"tee saw:\", seen.String())\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the real output from our run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hello from a string\ncopied bytes: 20\nQUIET TEXT\nscanned: line one\nscanned: line two\nscanned: line three\nlogged twice\nbuffer=\"logged twice\\n\" counted=13\nlimited: 0123\ntee saw: tee data<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, <code>io.Copy<\/code> sent a string to the screen and reported 20 bytes. Then our custom reader changed the text to upper case on the way through. The scanner gave us one line at a time. Next, <code>MultiWriter<\/code> wrote the same message to the screen, to a buffer and to our counter, which saw 13 bytes. After that, the limit reader stopped after four characters. Finally, the tee reader kept a copy of what passed by. These lines show the Go Reader and Writer interfaces doing real work. Also, none of the helpers knew about our types.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Reader and Writer Interfaces<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ignoring the byte count<\/strong>: a reader may return fewer bytes than the slice holds. So always use <code>n<\/code>, not <code>len(p)<\/code>.<\/li>\n\n\n\n<li><strong>Treating io.EOF as a failure<\/strong>: it only means the data ended. Therefore, check for it before you log an error.<\/li>\n\n\n\n<li><strong>Reading a huge body with io.ReadAll<\/strong>: this can fill the memory. Instead, wrap the reader in <code>io.LimitReader<\/code> first.<\/li>\n\n\n\n<li><strong>Forgetting to close<\/strong>: files and response bodies need <code>Close<\/code>. So use <code>defer<\/code> right after a successful open.<\/li>\n\n\n\n<li><strong>Writing with a value receiver when state is needed<\/strong>: the counter would reset on every call. For that reason, use a pointer receiver.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Reader and Writer Interfaces<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Accept io.Reader and io.Writer in your functions<\/strong>, because callers can then pass files, buffers or strings.<\/li>\n\n\n\n<li><strong>Return concrete types<\/strong> when you create something, since callers get all its methods.<\/li>\n\n\n\n<li><strong>Use strings.NewReader in tests<\/strong>, which avoids real files.<\/li>\n\n\n\n<li><strong>Wrap readers instead of copying data<\/strong>, because wrapping keeps memory use low.<\/li>\n\n\n\n<li><strong>Limit untrusted input<\/strong>, since a client can send any amount of data.<\/li>\n\n\n\n<li><strong>Keep your own Read and Write methods small<\/strong>, so they follow the interface rules.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise the Go Reader and Writer interfaces, write a <code>rot13Reader<\/code> that wraps another reader and applies ROT13 to letters. Then copy <code>\"Uryyb\"<\/code> through it to the screen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: follow the pattern of <code>upperReader<\/code>. Loop over the first <code>n<\/code> bytes of <code>p<\/code>, and change only letters. After that, run it twice in a row and check that you get the original text back.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages describe the packages and ideas used in this lesson.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/io\">io package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/bufio\">bufio package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/tour\/methods\/21\">Tour of Go: Readers<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Go Reader and Writer interfaces each have one method, <code>Read<\/code> and <code>Write<\/code>.<\/li>\n\n\n\n<li>A reader signals the end of data with <code>io.EOF<\/code>.<\/li>\n\n\n\n<li><code>io.Copy<\/code> moves data in small chunks, so memory use stays low.<\/li>\n\n\n\n<li>Helpers such as <code>LimitReader<\/code>, <code>TeeReader<\/code> and <code>MultiWriter<\/code> wrap readers and writers.<\/li>\n\n\n\n<li>Accept the interfaces in your functions, and tests become simple.<\/li>\n\n\n\n<li>You can stack helpers to build small data pipelines.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can read, write and combine data from any source. That wraps up this group of lessons on building real services in Go. Later, we will keep going with more practical topics for your daily work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Coming soon: Go build tags and conditional compilation<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>The Go Reader and Writer interfaces are two tiny interfaces that move data between files, networks, strings and more. In this post, you will&hellip;<\/p>\n","protected":false},"author":1,"featured_media":453,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,94,77],"swapz_series":[],"class_list":["post-475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-reader-and-writer","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Reader and Writer Interfaces Explained Simply<\/title>\n<meta name=\"description\" content=\"Learn the Go Reader and Writer interfaces. Build a custom reader and writer, then use io.Copy, MultiWriter and TeeReader with real examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Reader and Writer Interfaces Explained Simply\" \/>\n<meta property=\"og:description\" content=\"Learn the Go Reader and Writer interfaces. Build a custom reader and writer, then use io.Copy, MultiWriter and TeeReader with real examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-07T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Reader and Writer Interfaces Explained Simply\",\"datePublished\":\"2026-06-07T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/\"},\"wordCount\":1505,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-io-reader-writer-featured.png\",\"keywords\":[\"Go Lang\",\"Go Reader and Writer\",\"Intermediate\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/\",\"name\":\"Go Reader and Writer Interfaces Explained Simply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-io-reader-writer-featured.png\",\"datePublished\":\"2026-06-07T03:30:00+00:00\",\"description\":\"Learn the Go Reader and Writer interfaces. Build a custom reader and writer, then use io.Copy, MultiWriter and TeeReader with real examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-io-reader-writer-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-io-reader-writer-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Reader and Writer featured image: io.Reader, io.Writer and io.Copy cards\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-io-reader-writer\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Reader and Writer Interfaces Explained Simply\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Reader and Writer Interfaces Explained Simply","description":"Learn the Go Reader and Writer interfaces. Build a custom reader and writer, then use io.Copy, MultiWriter and TeeReader with real examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/","og_locale":"en_US","og_type":"article","og_title":"Go Reader and Writer Interfaces Explained Simply","og_description":"Learn the Go Reader and Writer interfaces. Build a custom reader and writer, then use io.Copy, MultiWriter and TeeReader with real examples.","og_url":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-06-07T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Reader and Writer Interfaces Explained Simply","datePublished":"2026-06-07T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/"},"wordCount":1505,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-featured.png","keywords":["Go Lang","Go Reader and Writer","Intermediate"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/","url":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/","name":"Go Reader and Writer Interfaces Explained Simply","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-featured.png","datePublished":"2026-06-07T03:30:00+00:00","description":"Learn the Go Reader and Writer interfaces. Build a custom reader and writer, then use io.Copy, MultiWriter and TeeReader with real examples.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-io-reader-writer-featured.png","width":2400,"height":1260,"caption":"Go Reader and Writer featured image: io.Reader, io.Writer and io.Copy cards"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-io-reader-writer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Reader and Writer Interfaces Explained Simply"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/453"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=475"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}