Skip to content

Read from stdin #55

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

Open
sdmcallister opened this issue Apr 15, 2020 · 2 comments
Open

Read from stdin #55

sdmcallister opened this issue Apr 15, 2020 · 2 comments

Comments

@sdmcallister
Copy link

Does it make sense (or does it already exist) to add the capability to cat a file to a NimData Program? Something like
cat datafile | mynimdataprogram
Granted a file like the one above exists, and could be handled with the existing procs. But there are also situations where you might be following a file that has new data regularly added and you may want to peridiocally show the result.

@bluenote10
Copy link
Owner

On first glance reading from stdin seems like a reasonable idea.

@sdmcallister
Copy link
Author

I'm a bit of a noob so there is likely a better way, but I was getting this to work:

type
  StreamRowsDataFrame = ref object of DataFrame[string]
    hasHeader: bool

method iter*(df: StreamRowsDataFrame): (iterator(): string) =
  result = iterator(): string =
    if df.hasHeader:
      discard stdin.readLine()
    while not endOfFile(stdin):
      yield stdin.readLine()

proc fromStream*(dfc: DataFrameContext,
               hasHeader: bool = true): DataFrame[string] =

  result = StreamRowsDataFrame(
    hasHeader: hasHeader
  )

I'd like to eventually learn and contribute more.

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

No branches or pull requests

2 participants