Update ch5-08.md

同上次一样,结尾加粗样式丢失
pull/118/head
Asakijz 2022-09-05 11:25:18 +08:00 committed by GitHub
parent 0c05463c23
commit f9ccbec80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -221,4 +221,4 @@ func fetch(url string) (filename string, n int64, err error) {
对resp.Body.Close延迟调用我们已经见过了在此不做解释。上例中通过os.Create打开文件进行写入在关闭文件时我们没有对f.close采用defer机制因为这会产生一些微妙的错误。许多文件系统尤其是NFS写入文件时发生的错误会被延迟到文件关闭时反馈。如果没有检查文件关闭时的反馈信息可能会导致数据丢失而我们还误以为写入操作成功。如果io.Copy和f.close都失败了我们倾向于将io.Copy的错误信息反馈给调用者因为它先于f.close发生更有可能接近问题的本质。
**练习5.18**不修改fetch的行为重写fetch函数要求使用defer机制关闭文件。
**练习5.18** 不修改fetch的行为重写fetch函数要求使用defer机制关闭文件。