Skip to content

Commit

Permalink
Rename type bigstring to buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed May 11, 2021
1 parent 0f2df71 commit 1386bf3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
22 changes: 11 additions & 11 deletions docs/web/postprocess/index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -665,44 +665,44 @@ let cookie_replacement = {|
</pre>
|}

let bigstring_expected = {|<div class="spec type" id="type-bigstring">
<a href="#type-bigstring" class="anchor"></a><code><span><span class="keyword">type</span> bigstring</span><span> = <span><span>(char,&nbsp;<span class="xref-unresolved">Stdlib</span>.Bigarray.int8_unsigned_elt,&nbsp;<span class="xref-unresolved">Stdlib</span>.Bigarray.c_layout)</span> <span class="xref-unresolved">Stdlib</span>.Bigarray.Array1.t</span></span></code>
let bigstring_expected = {|<div class="spec type" id="type-buffer">
<a href="#type-buffer" class="anchor"></a><code><span><span class="keyword">type</span> buffer</span><span> = <span><span>(char,&nbsp;<span class="xref-unresolved">Stdlib</span>.Bigarray.int8_unsigned_elt,&nbsp;<span class="xref-unresolved">Stdlib</span>.Bigarray.c_layout)</span> <span class="xref-unresolved">Stdlib</span>.Bigarray.Array1.t</span></span></code>
</div>
|}

let bigstring_replacement = {|
<pre><span class="keyword">type</span> bigstring =
<pre><span class="keyword">type</span> buffer =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout)
Bigarray.Array1.t
</pre>
|}

let next_expected = {|<div class="spec value" id="val-next">
<a href="#val-next" class="anchor"></a><code><span><span class="keyword">val</span> next : <span>bigstring:<span>(<span><a href="#type-bigstring">bigstring</a> <span class="arrow">-&gt;</span></span> <span>int <span class="arrow">-&gt;</span></span> <span>int <span class="arrow">-&gt;</span></span> unit)</span> <span class="arrow">-&gt;</span></span> <span>close:<span>(<span>unit <span class="arrow">-&gt;</span></span> unit)</span> <span class="arrow">-&gt;</span></span> <span>exn:<span>(<span>exn <span class="arrow">-&gt;</span></span> unit)</span> <span class="arrow">-&gt;</span></span>
<a href="#val-next" class="anchor"></a><code><span><span class="keyword">val</span> next : <span>buffer:<span>(<span><a href="#type-buffer">buffer</a> <span class="arrow">-&gt;</span></span> <span>int <span class="arrow">-&gt;</span></span> <span>int <span class="arrow">-&gt;</span></span> unit)</span> <span class="arrow">-&gt;</span></span> <span>close:<span>(<span>unit <span class="arrow">-&gt;</span></span> unit)</span> <span class="arrow">-&gt;</span></span> <span>exn:<span>(<span>exn <span class="arrow">-&gt;</span></span> unit)</span> <span class="arrow">-&gt;</span></span>
<span><a href="#type-request">request</a> <span class="arrow">-&gt;</span></span> unit</span></code>
</div>
|}

let next_replacement = {|
<pre><span class="keyword">val</span> next :
bigstring:(<a href="#type-bigstring">bigstring</a> -> int -> int -> unit) ->
buffer:(<a href="#type-buffer">buffer</a> -> int -> int -> unit) ->
close:(unit -> unit) ->
exn:(exn -> unit) ->
<a href="#type-request">request</a> ->
unit
</pre>
|}

let write_bigstring_expected = {|<div class="spec value" id="val-write_bigstring">
<a href="#val-write_bigstring" class="anchor"></a><code><span><span class="keyword">val</span> write_bigstring : <span>?offset:int <span class="arrow">-&gt;</span></span> <span>?length:int <span class="arrow">-&gt;</span></span> <span><a href="#type-response">response</a> <span class="arrow">-&gt;</span></span> <span><a href="#type-bigstring">bigstring</a> <span class="arrow">-&gt;</span></span> <span>unit <a href="#type-promise">promise</a></span></span></code>
let write_bigstring_expected = {|<div class="spec value" id="val-write_buffer">
<a href="#val-write_buffer" class="anchor"></a><code><span><span class="keyword">val</span> write_buffer : <span>?offset:int <span class="arrow">-&gt;</span></span> <span>?length:int <span class="arrow">-&gt;</span></span> <span><a href="#type-response">response</a> <span class="arrow">-&gt;</span></span> <span><a href="#type-buffer">buffer</a> <span class="arrow">-&gt;</span></span> <span>unit <a href="#type-promise">promise</a></span></span></code>
</div>
|}

let write_bigstring_replacement = {|
<pre><span class="keyword">val</span> write_bigstring :
<pre><span class="keyword">val</span> write_buffer :
?offset:int ->
?length:int ->
<a href="#type-response">response</a> -> <a href="#type-bigstring">bigstring</a> -> unit <a href="#type-promise">promise</a>
<a href="#type-response">response</a> -> <a href="#type-buffer">buffer</a> -> unit <a href="#type-promise">promise</a>
</pre>
|}

Expand Down Expand Up @@ -1599,7 +1599,7 @@ let pretty_print_signatures soup =

multiline "#val-cookie" cookie_expected cookie_replacement;

let bigstring = soup $ "#type-bigstring" in
let bigstring = soup $ "#type-buffer" in
if_expected
bigstring_expected
(fun () -> pretty_print bigstring)
Expand All @@ -1615,7 +1615,7 @@ let pretty_print_signatures soup =
Soup.replace (next $ "> code") (Soup.parse next_replacement);
Soup.add_class "multiline" next);

let write_bigstring = soup $ "#val-write_bigstring" in
let write_bigstring = soup $ "#val-write_buffer" in
if_expected
write_bigstring_expected
(fun () -> pretty_print write_bigstring)
Expand Down
4 changes: 2 additions & 2 deletions src/dream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ end
include Dream__pure.Inmost

(* Eliminate optional arguments from the public interface for now. *)
let next ~bigstring ~close ~exn request =
next ~bigstring ~close ~exn request
let next ~buffer ~close ~exn request =
next ~buffer ~close ~exn request

include Dream__middleware.Log
include Dream__middleware.Echo
Expand Down
16 changes: 8 additions & 8 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,12 @@ val close_stream : response -> unit promise

(** {2 Low-level streaming} *)

type bigstring =
type buffer =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
(** Byte arrays in the C heap. See
{{:http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.Array1.html}
[Bigarray.Array1]}. This type is also found in several libraries installed
by Dream, so their functions can be used with {!Dream.bigstring}:
by Dream, so their functions can be used with {!Dream.buffer}:
- {{:https://github.com/inhabitedtype/bigstringaf/blob/353cb283aef4c261597f68154eb27a138e7ef112/lib/bigstringaf.mli}
[Bigstringaf.t]} in bigstringaf.
Expand All @@ -702,7 +702,7 @@ type bigstring =
[Cstruct.buffer]} in Cstruct. *)

val next :
bigstring:(bigstring -> int -> int -> unit) ->
buffer:(buffer -> int -> int -> unit) ->
(* ?string:(string -> int -> int -> unit) ->
?flush:(unit -> unit) -> *)
close:(unit -> unit) ->
Expand All @@ -711,14 +711,14 @@ val next :
unit
(** Waits for the next stream event, and calls:
- [~bigstring] with an offset and length, if a {!bigstring} is written,
- [~buffer] with an offset and length, if a {!type-buffer} is written,
- [~close] if close is requested, and
- [~exn] to report an exception. *)

val write_bigstring :
?offset:int -> ?length:int -> response -> bigstring -> unit promise
(** Streams out the {!bigstring} slice. [~offset] defaults to zero. [~length]
defaults to the length of the {!bigstring}, minus [~offset]. *)
val write_buffer :
?offset:int -> ?length:int -> response -> buffer -> unit promise
(** Streams out the {!buffer} slice. [~offset] defaults to zero. [~length]
defaults to the length of the {!buffer}, minus [~offset]. *)



Expand Down
8 changes: 4 additions & 4 deletions src/http/adapt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ let address_to_string : Unix.sockaddr -> string = function
let forward_body_general
(response : Dream.response)
(write_string : ?off:int -> ?len:int -> string -> unit)
(write_bigstring : ?off:int -> ?len:int -> Dream.bigstring -> unit)
(write_buffer : ?off:int -> ?len:int -> Dream.buffer -> unit)
http_flush
close =

let rec send () =
response
|> Dream.next
~bigstring
~buffer
~string
~flush
~close
~exn:ignore

and bigstring chunk off len =
write_bigstring ~off ~len chunk;
and buffer chunk off len =
write_buffer ~off ~len chunk;
send ()

and string chunk off len =
Expand Down
14 changes: 4 additions & 10 deletions src/pure/inmost.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
include Method
include Status

type bigstring = Body.bigstring
type buffer = Body.bigstring

(* Used for converting the stream interface of [multipart_form] into the pull
interface of Dream.
Expand Down Expand Up @@ -257,11 +257,8 @@ let body message =
let read message =
Body.read message.body

let next ~bigstring ?string ?flush ~close ~exn message =
Body.next ~bigstring ?string ?flush ~close ~exn message.body

(* let body_stream_bigstring data eof message =
Body.body_stream_bigstring data eof message.body *)
let next ~buffer ?string ?flush ~close ~exn message =
Body.next ~bigstring:buffer ?string ?flush ~close ~exn message.body

(* Create a fresh ref. The reason this field has a ref is because it might get
replaced when a body is forced read. That's not what's happening here - we
Expand All @@ -285,7 +282,7 @@ let with_stream message =
let write message chunk =
Body.write chunk message.body

let write_bigstring ?(offset = 0) ?length message chunk =
let write_buffer ?(offset = 0) ?length message chunk =
let length =
match length with
| Some length -> length
Expand All @@ -299,9 +296,6 @@ let flush message =
let close_stream message =
Body.close_stream message.body

(* let with_body_stream_bigstring stream message =
update {message with body = ref (`Bigstring_stream stream)} *)

let has_body message =
Body.has_body message.body

Expand Down
4 changes: 2 additions & 2 deletions test/expect/pure/body.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let bigstring_stream chunks =
Dream.close_stream response
| chunk::more ->
chunks := more;
let%lwt () = Dream.write_bigstring response (Lwt_bytes.of_string chunk) in
let%lwt () = Dream.write_buffer response (Lwt_bytes.of_string chunk) in
push ()
in
Lwt.async push;
Expand Down Expand Up @@ -151,7 +151,7 @@ let next message =
let until_done, signal_done = Lwt.wait () in
let rec next accumulator =
Dream__pure.Inmost.next
~bigstring:(fun data start length ->
~buffer:(fun data start length ->
next
((Lwt_bytes.to_string
(Lwt_bytes.proxy data start length))::accumulator))
Expand Down

0 comments on commit 1386bf3

Please sign in to comment.