Create ( filename ) if err!= nil { return err } defer safeClose ( f, & err ) _, err = f. Write ( data ) return err } The code looks almost the same as in the first example, but this time it’s actually correct.
O_TRUNC, perm ) if err!= nil { return err } n, err := f. Write ( data ) if err == nil && n < len ( data ) { err = io.