From afaa5d561826ccf7cab4fde2af9ad39d32ea4d0d Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Fri, 4 Apr 2008 03:10:34 +0000 Subject: compaction code, not hooked up to webserver yet git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@644593 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_stream.erl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/couchdb/couch_stream.erl') diff --git a/src/couchdb/couch_stream.erl b/src/couchdb/couch_stream.erl index ae1b4f2c..8d5260f1 100644 --- a/src/couchdb/couch_stream.erl +++ b/src/couchdb/couch_stream.erl @@ -15,7 +15,7 @@ -export([test/1]). -export([open/1, open/2, close/1, read/3, read_term/2, write/2, write_term/2, get_state/1, foldl/5]). --export([copy/4]). +-export([copy/4, copy_to_new_stream/4]). -export([ensure_buffer/2, set_min_buffer/2]). -export([init/1, terminate/2, handle_call/3]). -export([handle_cast/2,code_change/3,handle_info/2]). @@ -78,10 +78,16 @@ read(Fd, Sp, Num) -> Bin = list_to_binary(lists:reverse(RevBin)), {ok, Bin, Sp2}. -copy(#stream{pid = _Pid, fd = Fd}, Sp, Num, DestStream) -> - copy(Fd, Sp, Num, DestStream); -copy(Fd, Sp, Num, DestStream) -> - {ok, NewSp, _Sp2} = stream_data(Fd, Sp, Num, ?HUGE_CHUNK, +copy_to_new_stream(Src, Sp, Len, DestFd) -> + Dest = open(DestFd), + {ok, NewSp} = copy(Src, Sp, Len, Dest), + close(Dest), + {ok, NewSp}. + +copy(#stream{pid = _Pid, fd = Fd}, Sp, Len, DestStream) -> + copy(Fd, Sp, Len, DestStream); +copy(Fd, Sp, Len, DestStream) -> + {ok, NewSp, _Sp2} = stream_data(Fd, Sp, Len, ?HUGE_CHUNK, fun(Bin, AccPointer) -> {ok, NewPointer} = write(DestStream, Bin), if AccPointer == null -> NewPointer; true -> AccPointer end -- cgit v1.2.3