-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ole Rixmann
committed
Sep 9, 2015
1 parent
446f9da
commit 2323e28
Showing
5 changed files
with
61 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Ecto.Export.Stream.File do | ||
alias Ecto.Export.Dispatcher | ||
|
||
def send_stream formatted_entries, filename do | ||
filehandle = File.open! filename, [:write, :utf8] | ||
Enum.map formatted_entries, &IO.write(filehandle, &1) | ||
File.close filehandle | ||
end | ||
|
||
def receive_stream filename do | ||
Stream.resource( | ||
fn -> {File.open!(filename, [:read, :utf8]), 0} end, | ||
fn {filehandle, linecount} -> | ||
case IO.read(filehandle, :line) do | ||
:eof -> {:halt, filehandle} | ||
{:error, _} = _err -> {:halt, filehandle} | ||
data -> | ||
Dispatcher.progress_update({:read_file, linecount}) | ||
{[data], {filehandle, linecount + 1}} | ||
end | ||
end, | ||
fn filehandle -> File.close(filehandle) end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters