Module Stdlib.Out_channel
Contents
Instructions: Use this module in your project
In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:
Add the following to your project's
dependencies/CMakeLists.txt:DkSDKProject_DeclareAvailable(ocaml CONSTRAINT "= 4.14.0" FINDLIBS str unix runtime_events threads dynlink) DkSDKProject_MakeAvailable(ocaml)Add the
Findlib::ocamllibrary to any desired targets insrc/*/CMakeLists.txt:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::ocaml)Click your IDE's
Buildbutton
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install ocaml.4.14.0Edit your
dune-projectand add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (ocaml (>= 4.14.0))))Then run:
dune build *.opam # if this fails, run: dune buildEdit your
<package>.opamfile and add:depends: [ # ... existing dependencies ... "ocaml" {>= "4.14.0"} ]Then run:
opam install . --deps-only
FINALLY, add the library to any desired (library)and/or (executable) targets in your **/dune files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
))typet`` =out_channel
The type of output channel.
typeopen_flag`` =open_flag=
|Open_rdonly(* open for reading.
*)
|Open_wronly(* open for writing.
*)
|Open_append(* open for appending: always write at end of file.
*)
|Open_creat(* create the file if it does not exist.
*)
|Open_trunc(* empty the file if it already exists.
*)
|Open_excl(* fail if Open_creat and the file already exists.
*)
|Open_binary(* open in binary mode (no conversion).
*)
|Open_text(* open in text mode (may perform conversions).
*)
|Open_nonblock(* open in non-blocking mode.
*)
Opening modes for open_gen.
valstdout :t
The standard output for the process.
valstderr :t
The standard error output for the process.
valopen_bin : ``string->t
Open the named file for writing, and return a new output channel on that file, positioned at the beginning of the file. The file is truncated to zero length if it already exists. It is created if it does not already exists.
valopen_text : ``string->t
valwith_open_bin : ``string->``(t->'a)``->'a
with_open_bin fn f opens a channel oc on file fn and returns
f oc. After f returns, either with a value or by raising an
exception, oc is guaranteed to be closed.
valwith_open_text : ``string->``(t->'a)``->'a
Like with_open_bin, but the channel is opened in
text mode (see open_text).
Like with_open_bin, but can specify the opening
mode and file permission, in case the file must be created (see
open_gen).
valseek :t->``int64->unit
seek chan pos sets the current writing position to pos for channel
chan. This works only for regular files. On files of other kinds (such
as terminals, pipes and sockets), the behavior is unspecified.
valpos :t->int64
Return the current writing position for the given channel. Does not work
on channels opened with the Open_append flag (returns unspecified
results).
For files opened in text mode under Windows, the returned position is
approximate (owing to end-of-line conversion); in particular, saving the
current position with pos, then going back to this
position using seek will not work. For this programming
idiom to work reliably and portably, the file must be opened in binary
mode.
vallength :t->int64
Return the size (number of characters) of the regular file on which the given channel is opened. If the channel is opened on a file that is not a regular file, the result is meaningless.
valclose :t->unit
Close the given channel, flushing all buffered write operations. Output
functions raise a Sys_error exception when they are applied to a
closed output channel, except close and
flush, which do nothing when applied to an already
closed channel. Note that close may raise Sys_error if
the operating system signals an error when flushing or closing.
valflush :t->unit
Flush the buffer associated with the given output channel, performing all pending writes on that channel. Interactive programs must be careful about flushing standard output and standard error at the right time.
valflush_all : ``unit->unit
Flush all open output channels; ignore errors.
valoutput_char :t->``char->unit
Write the character on the given output channel.
valoutput_byte :t->``int->unit
Write one 8-bit integer (as the single character with that code) on the given output channel. The given integer is taken modulo 256.
valoutput_string :t->``string->unit
Write the string on the given output channel.
valoutput_bytes :t->``bytes->unit
Write the byte sequence on the given output channel.
valoutput :t->``bytes->``int->``int->unit
output oc buf pos len writes len characters from byte sequence
buf, starting at offset pos, to the given output channel oc.
-
raises Invalid_argument
if
posandlendo not designate a valid range ofbuf.
valoutput_substring :t->``string->``int->``int->unit
Same as output but take a string as argument instead of
a byte sequence.
valset_binary_mode :t->``bool->unit
set_binary_mode oc true sets the channel oc to binary mode: no
translations take place during output.
set_binary_mode oc false sets the channel oc to text mode: depending
on the operating system, some translations may take place during output.
For instance, under Windows, end-of-lines will be translated from \n
to \r\n.
This function has no effect under operating systems that do not distinguish between text mode and binary mode.
valset_buffered :t->``bool->unit
set_buffered oc true sets the channel oc to buffered mode. In this
mode, data output on oc will be buffered until either the internal
buffer is full or the function flush or
flush_all is called, at which point it will be sent
to the output device.
set_buffered oc false sets the channel oc to unbuffered mode. In
this mode, data output on oc will be sent to the output device
immediately.
All channels are open in buffered mode by default.
valis_buffered :t->bool
is_buffered oc returns whether the channel oc is buffered (see
set_buffered).
