package mlgpx

  1. Overview
  2. Docs

Module Gpx_eioSource

Eio API for GPX operations

This module provides a direct-style API for GPX operations using Eio's effects-based concurrent I/O system. It offers convenient functions for common GPX operations while maintaining structured concurrency.

Usage Example

  open Gpx_eio

  let main env =
    let fs = Eio.Stdenv.fs env in
    
    (* Create a GPX document *)
    let lat = Gpx.Coordinate.latitude 37.7749 |> Result.get_ok in
    let lon = Gpx.Coordinate.longitude (-122.4194) |> Result.get_ok in
    let wpt = Gpx.Waypoint.make lat lon |> Gpx.Waypoint.with_name "San Francisco" in
    let gpx = Gpx.make_gpx ~creator:"eio-example" |> Gpx.Doc.add_waypoint wpt in
    
    (* Write with validation *)
    write ~validate:true fs "output.gpx" gpx;
    
    (* Read it back *)
    let gpx2 = read ~validate:true fs "output.gpx" in
    Printf.printf "Read %d waypoints\n" (List.length (Gpx.Doc.waypoints gpx2))

  let () = Eio_main.run main

Module Re-exports

Sourcemodule IO : sig ... end

GPX Eio I/O operations

Convenience File Operations

These functions provide simple file I/O with the filesystem from Eio.Stdenv.fs.

Sourceval read : ?validate:bool -> fs:[> Eio.Fs.dir_ty ] Eio.Path.t -> string -> Gpx.t

Read and parse GPX file.

  • parameter fs

    Filesystem capability

  • parameter path

    File path to read

  • parameter ?validate

    Optional validation flag (default: false)

  • returns

    GPX document

Sourceval write : ?validate:bool -> fs:[> Eio.Fs.dir_ty ] Eio.Path.t -> string -> Gpx.t -> unit

Write GPX to file.

  • parameter fs

    Filesystem capability

  • parameter path

    File path to write

  • parameter gpx

    GPX document to write

  • parameter ?validate

    Optional validation flag (default: false)

Sourceval write_with_backup : ?validate:bool -> fs:[> Eio.Fs.dir_ty ] Eio.Path.t -> string -> Gpx.t -> string

Write GPX to file with automatic backup.

  • parameter fs

    Filesystem capability

  • parameter path

    File path to write

  • parameter gpx

    GPX document to write

  • parameter ?validate

    Optional validation flag (default: false)

  • returns

    Backup file path (empty if no backup created)

Stream Operations

Operations for reading/writing GPX from/to Eio flows.

Sourceval from_source : ?validate:bool -> [> Eio.Flow.source_ty ] Eio.Resource.t -> Gpx.t

Read GPX from Eio source.

  • parameter source

    Input flow

  • parameter ?validate

    Optional validation flag (default: false)

  • returns

    GPX document

Sourceval to_sink : ?validate:bool -> [> Eio.Flow.sink_ty ] Eio.Resource.t -> Gpx.t -> unit

Write GPX to Eio sink.

  • parameter sink

    Output flow

  • parameter gpx

    GPX document

  • parameter ?validate

    Optional validation flag (default: false)

Sourceval print_stats : [> Eio.Flow.sink_ty ] Eio.Resource.t -> Gpx.t -> unit

Print GPX statistics to sink.

  • parameter sink

    Output sink

  • parameter gpx

    GPX document

OCaml

Innovation. Community. Security.