From 13891d428f18dbbe24fe16be8b18e7d912f71976 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Thu, 4 Nov 2021 09:39:02 -0700 Subject: [PATCH] os: add File.WriteString and File.WriteAt WriteString just does the simple and and converts the passed string to a byte-slice. This can be made zero-copy later with unsafe, if needed. WriteAt returns ErrNotImplemented, to match Seek() and ReadAt(). Fixes #2157 --- src/os/file.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/os/file.go b/src/os/file.go index 86db953e..ca6cdf6d 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -111,6 +111,16 @@ func (f *File) Write(b []byte) (n int, err error) { return } +// WriteString is like Write, but writes the contents of string s rather than a +// slice of bytes. +func (f *File) WriteString(s string) (n int, err error) { + return f.Write([]byte(s)) +} + +func (f *File) WriteAt(b []byte, off int64) (n int, err error) { + return 0, ErrNotImplemented +} + // Close closes the File, rendering it unusable for I/O. func (f *File) Close() (err error) { err = f.handle.Close()