Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[node] 关于 res.end 概念问题 #1

Open
kitebear opened this issue Dec 9, 2015 · 2 comments
Open

[node] 关于 res.end 概念问题 #1

kitebear opened this issue Dec 9, 2015 · 2 comments
Labels

Comments

@kitebear
Copy link
Member

kitebear commented Dec 9, 2015

4n 0 5 1r 1r1019u4 s5
最后一句res.end("hello world") 导致页面图片不出现
原因:
end会触发write的如果参数为data(buffer chunk or string utf-8)
end为阻塞操作,pipe为无阻塞操作,所以优先执行end,end终结了一次请求的完整过程,所以导致图片不出现
如果图片src为undefined
就会默认请求当前页面链接

@kitebear kitebear changed the title 关于 res.end 概念问题 [Node] 关于 res.end 概念问题 Dec 9, 2015
@VaJoy VaJoy changed the title [Node] 关于 res.end 概念问题 [node] 关于 res.end 概念问题 Dec 9, 2015
@coxo
Copy link
Member

coxo commented Dec 9, 2015

创建此Server后,用户访问请求过来,Server会创建一个可读流,当调用.pipe(res)为可读流指定目标后,可读流(stream)会开始从文件中读取数据,数据写入res(可写流)完毕后,自动调用res的end()方法,结束响应,可写流不再写入。

@coxo
Copy link
Member

coxo commented Dec 9, 2015

可写流重要的两个方法:write和end

write:该方法向底层系统写入数据,并在数据被处理完毕后调用所给的回调。
end:当不再写入数据时,调用该方法,停止写入。

在调用end()后,再调用write()方法会产生错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants