Fs2DataSource

io.dylemma.spac.xml.Fs2DataSource
object Fs2DataSource

Provides helpers for creating FS2 streams of io.dylemma.spac.xml.XmlEvent, using fs2-data-xml as the underlying event provider.

Fs2-data is already pretty "plug-and-play", so at best this helper just removes a few steps/pipes that you would have to manually call.

For example:

  val charStream: Stream[IO, Char] = ???

  // this...
  val xmlStream1: Stream[IO, XmlEvent] = {
    import fs2.data.xml._
    charStream
      .through(events)
      .through(namespaceResolver)
      .through(reverenceResolver())
      .through(normalize)
      .through(Fs2DataSource.convert)
  }

  // could be replaced with
  val xmlStream2: Stream[IO, XmlEvent] = {
    Fs2DataSource.fromRawXmlStream(charStream)
  }

Essentially this helper just provides a convenient apply method that accepts String, Stream[F, Char], Stream[F, String], or Stream[F, fs2.data.xml.XmlEvent] to return a Stream[F, XmlEvent] which an XmlParser could then interact with.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

object Cleanup extends Cleanup

Default cleanup function which passes the input stream through namespaceResolver (with default args), then a default referenceResolver, then normalize

Default cleanup function which passes the input stream through namespaceResolver (with default args), then a default referenceResolver, then normalize

Attributes

Companion
trait
Supertypes
trait Cleanup
class Object
trait Matchable
class Any
Self type
Cleanup.type
trait Cleanup

Represents some post-processing on a stream of fs2-data-xml XmlEvent, e.g. piping the stream through a resolver and/or normalizer.

Represents some post-processing on a stream of fs2-data-xml XmlEvent, e.g. piping the stream through a resolver and/or normalizer.

This is how the ToFs2XmlEventStream typeclass allows you to override the stream creation behavior for the instances that use the events pipe themselves.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Cleanup.type
object NoCleanup.type
object NoCleanup extends Cleanup

No-op cleanup function which returns the input stream unmodified

No-op cleanup function which returns the input stream unmodified

Attributes

Supertypes
trait Cleanup
class Object
trait Matchable
class Any
Self type
NoCleanup.type

Value members

Concrete methods

def convert[F[_]]: (F, XmlEvent) => XmlEvent

Pipe for converting fs2.data.xml.XmlEvent to io.dylemma.spac.xml.XmlEvent. This will be used under the hood of the apply and syncIO helpers, but is being made available to allow for manual stream creation if desired. The stream of fs2-data XmlEvents should ideally already be passed through a referenceResolver and normalize pipe before this one.

Pipe for converting fs2.data.xml.XmlEvent to io.dylemma.spac.xml.XmlEvent. This will be used under the hood of the apply and syncIO helpers, but is being made available to allow for manual stream creation if desired. The stream of fs2-data XmlEvents should ideally already be passed through a referenceResolver and normalize pipe before this one.

Attributes

def fromRawXmlStream[F[_], A](rawXmlStream: Stream[F, A], cleanup: Cleanup)(implicit A: CharLikeChunks[F, A], F: MonadError[F, Throwable]): Stream[F, XmlEvent]

Converts a stream of raw XML data (such as Strings, Characters, or Bytes) to a stream of XmlEvents.

Converts a stream of raw XML data (such as Strings, Characters, or Bytes) to a stream of XmlEvents.

Under the hood, this calls events[F, A] from fs2-data-xml, piped through the cleanup functions (i.e. namespaceResolver, referenceResolver, normalize), then converts the fs2-data based XML events to the SPaC model of XmlEvent

Type parameters

A

The chunk type of the raw XML data, i.e. String, Char, or Byte

F

Stream effect type

Value parameters

A

Evidence that the A type can be treated as raw xml by fs2-data-xml

F

Evidence that errors can be thrown in the F effect context

cleanup

Cleanup function used on the fs2-data XmlEvents. By default this will pass the events through namespaceResolver through referenceResolver() through normalize.

rawXmlStream

The raw XML data

Attributes

Returns

A stream of SPaC XmlEvents

def fromString[F[_]](rawXml: String, cleanup: Cleanup)(implicit F: MonadError[F, Throwable]): Stream[F, XmlEvent]

Converts a raw XML string (expected to contain a complete XML document) to a stream of XmlEvents.

Converts a raw XML string (expected to contain a complete XML document) to a stream of XmlEvents.

Type parameters

F

Stream effect type

Value parameters

F

Evidence that errors can be thrown in the F effect context

cleanup

Cleanup function used on the fs2-data XmlEvents. By default this will pass the events through namespaceResolver through referenceResolver() through normalize.

rawXml

The raw XML data

Attributes

Returns

A stream of SPaC XmlEvents