stream

What does “Stream did not contain valid UTF-8” mean?

一个人想着一个人 提交于 2020-05-15 03:46:21
问题 I'm creating a simple HTTP server. I need to read the requested image and send it to browser. I'm using this code: fn read_file(mut file_name: String) -> String { file_name = file_name.replace("/", ""); if file_name.is_empty() { file_name = String::from("index.html"); } let path = Path::new(&file_name); if !path.exists() { return String::from("Not Found!"); } let mut file_content = String::new(); let mut file = File::open(&file_name).expect("Unable to open file"); let res = match file.read_to

What does “Stream did not contain valid UTF-8” mean?

馋奶兔 提交于 2020-05-15 03:45:07
问题 I'm creating a simple HTTP server. I need to read the requested image and send it to browser. I'm using this code: fn read_file(mut file_name: String) -> String { file_name = file_name.replace("/", ""); if file_name.is_empty() { file_name = String::from("index.html"); } let path = Path::new(&file_name); if !path.exists() { return String::from("Not Found!"); } let mut file_content = String::new(); let mut file = File::open(&file_name).expect("Unable to open file"); let res = match file.read_to

Koa2 - How to write to response stream?

孤街醉人 提交于 2020-05-13 02:56:42
问题 Using Koa2 and I'm not sure how to write data to the response stream, so in Express it would be something like: res.write('some string'); I understand that I can assign a stream to ctx.body but I'm not familiar with node.js streams too well so don't know how I would go about creating this stream. 回答1: The koa documentation allows you to assign a stream to your response: (from https://koajs.com/#response) ctx.response.body= Set response body to one of the following: string written Buffer

Koa2 - How to write to response stream?

微笑、不失礼 提交于 2020-05-13 02:56:26
问题 Using Koa2 and I'm not sure how to write data to the response stream, so in Express it would be something like: res.write('some string'); I understand that I can assign a stream to ctx.body but I'm not familiar with node.js streams too well so don't know how I would go about creating this stream. 回答1: The koa documentation allows you to assign a stream to your response: (from https://koajs.com/#response) ctx.response.body= Set response body to one of the following: string written Buffer

What's the difference between .pipe and pipeline on streams

巧了我就是萌 提交于 2020-05-09 06:06:10
问题 I found two different ways to pipe streams in node.js Well known .pipe() method of a stream https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options and standalone function for streams https://nodejs.org/api/stream.html#stream_stream_pipeline_streams_callback Which one should I use and what are the benefits between those two? 回答1: TL;DR - You better want to use pipeline What's pipeline? From the docs: A module method to pipe between streams forwarding errors and properly

What's the difference between .pipe and pipeline on streams

假装没事ソ 提交于 2020-05-09 06:03:05
问题 I found two different ways to pipe streams in node.js Well known .pipe() method of a stream https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options and standalone function for streams https://nodejs.org/api/stream.html#stream_stream_pipeline_streams_callback Which one should I use and what are the benefits between those two? 回答1: TL;DR - You better want to use pipeline What's pipeline? From the docs: A module method to pipe between streams forwarding errors and properly

Set std:cin to a string

↘锁芯ラ 提交于 2020-04-30 05:43:34
问题 For ease of testing I wish to set Cin's input to a string I can hardcode. For example, std::cin("test1 \ntest2 \n"); std::string str1; std::string str2; getline(cin,str1); getline(cin,str2); std::cout << str1 << " -> " << str2 << endl; Will read out: test1 -> test2 回答1: The best solution IMO is to refactor your core code to a function that accepts a std::istream reference: void work_with_input(std::istream& is) { std::string str1; std::string str2; getline(is,str1); getline(is,str2); std:

Set std:cin to a string

。_饼干妹妹 提交于 2020-04-30 05:36:28
问题 For ease of testing I wish to set Cin's input to a string I can hardcode. For example, std::cin("test1 \ntest2 \n"); std::string str1; std::string str2; getline(cin,str1); getline(cin,str2); std::cout << str1 << " -> " << str2 << endl; Will read out: test1 -> test2 回答1: The best solution IMO is to refactor your core code to a function that accepts a std::istream reference: void work_with_input(std::istream& is) { std::string str1; std::string str2; getline(is,str1); getline(is,str2); std:

Peek asio https ssl stream without deleting from input stream

拈花ヽ惹草 提交于 2020-04-17 18:58:34
问题 I am using asio standalone and an HTTPS wrapper from Eidheim (Eidheims SimpleHttpsServer) to set up an HTTPS server on Windows with asynchronous rerquest handling and a thread pool. Occassionally the HTTPS server gets raw socket queries though, because I want to replace an older socket server and if the client app is not up to date, they wont send HTTP(s) formatted queries. For HTTP this was no problem, because I could change the Read (from socket) method to use the legacy code for request

Nodejs Streams - Help find my memory leak

纵饮孤独 提交于 2020-04-17 18:56:50
问题 So I have a process that selects from a table. I partition my select programmatically into 20 sub-selects. I then go through each on of those select and stream its data to an indexing client (solr). Every select memory jumps up and holds until I get an OOM. I logged when each query went off and can be seen in in the following charts: These correlate with each jump in the this memory graph: 14 of 20 queries ran before I oomed. I see this behavior with code that is similar but with a delta that