Using r.ReadLine repeatedly I was able to read the full line in memory. It 
is working very fast.

for isPrefix && err == nil {
line, isPrefix, err = r.ReadLine()
ln = append(ln, line...)
}

if strings.Contains(s, "error") {

finds the substring very fast

Now is coming the last step - writing 100MB string to STDOUT
w io.Writer
w.Write([]byte(s))

It is too big and freezes with large string.

On Sunday, May 8, 2022 at 1:36:15 AM UTC-7 Tamás Gulácsi wrote:

> If that "100s of MB" is acceptable to be in memory, then bufio.Scanner 
> with properly sized scanner.Buffer is the easiest and battle tested 
> solution.
>
> If not, then you have to reimplement the same, with a temp file as a 
> buffer: read input, store in file, seeking to the start on each '\n', 
> copying the file to STDOUT when "test" is found.
> Not too hard, but have a few edge cases.
> Const V a következőt írta (2022. május 7., szombat, 22:40:58 UTC+2):
>
>> I need to write a program that reads STDIN and should output every line 
>> that contains a search word "test" to STDOUT. 
>>
>> How I can test that considering the problem is a line can be 100s of MB 
>> long (\n is line end) and tens of MB info is passed to it.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8af32d26-02b4-4dc1-8d0c-7baa29d06008n%40googlegroups.com.

Reply via email to