MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / loadPipeToBuffer

Function loadPipeToBuffer

io.go:634–729  ·  view source on GitHub ↗

load console pipe content to buffer (synchronous version)

(stdin io.Reader, b *Buffer)

Source from the content-addressed store, hash-verified

632
633// load console pipe content to buffer (synchronous version)
634func loadPipeToBuffer(stdin io.Reader, b *Buffer) error {
635 totalAddedLN := 0 //the number of lines has been added into buffer
636 var err error
637
638 // Create progress tracker (no file size for pipes)
639 progress := newProgressTracker(0, true)
640
641 scanner := bufio.NewScanner(stdin)
642 //increase buffer size for large files and long lines
643 const maxScanTokenSize = 1024 * 1024
644 buf := make([]byte, maxScanTokenSize)
645 scanner.Buffer(buf, maxScanTokenSize)
646 //read 10 lines to detect separator
647 lineNumber := 10
648 var detectLines []string //lines as detect separator data
649 if b.sep == 0 {
650 for scanner.Scan() {
651 line := scanner.Text()
652 //skip empty line
653 if line == "\n" {
654 continue
655 }
656 //ignore first n lines
657 if args.SkipNum > 0 {
658 args.SkipNum--
659 continue
660 }
661 //ignore line with specified prefix
662 if skipLine(line, args.SkipSymbol) {
663 continue
664 }
665 detectLines = append(detectLines, line)
666 if len(detectLines) >= lineNumber {
667 break
668 }
669 }
670 sd := sepDetecor{}
671 b.sep = sd.sepDetect(detectLines)
672 }
673 //check final separator
674 if b.sep == 0 {
675 fatalError(errors.New("tv can't identify separator, you need to set it manual"))
676 }
677
678 //add detectLines to buffer
679 for _, line := range detectLines {
680 //parse and add line to buffer
681 err = addDRToBuffer(b, line, args.ShowNum, args.HideNum)
682 if err != nil {
683 progress.finish()
684 return err
685 }
686 totalAddedLN++
687 progress.increment(int64(len(line) + 1))
688 if totalAddedLN >= args.NLine && args.NLine > 0 {
689 break
690 }
691 }

Callers 3

TestLoadPipeToBufferFunction · 0.85
mainFunction · 0.85

Calls 9

sepDetectMethod · 0.95
newProgressTrackerFunction · 0.85
skipLineFunction · 0.85
fatalErrorFunction · 0.85
addDRToBufferFunction · 0.85
finishMethod · 0.80
incrementMethod · 0.80
detectAllColumnTypesMethod · 0.80
enableStringInterningMethod · 0.80

Tested by 2

TestLoadPipeToBufferFunction · 0.68