file-uri-0.1.0.0: File URI parsing
Copyright(c) Soostone Inc. 2014-2015
Michael Xavier 2014-2015
Julian Ospald 2024
LicenseBSD3
Maintainerhasufell@posteo.de
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.URI.File

Description

System.URI.File aims to be an RFC8089 compliant URI file parser that uses efficient ByteStrings for parsing and representing the data.

As such it only parses a subset of RFC3986, but is better at interpreting the file paths. Filepaths are always absolute according to the spec.

Part of this module was ripped off of the uri-bytestring package from Soostone (specifically the host part parsing).

Synopsis

Data types

data FileURI Source #

A parsed file URI. It can have an auth/host part.

Constructors

FileURI 

Fields

Instances

Instances details
Show FileURI Source # 
Instance details

Defined in System.URI.File.Internal

Eq FileURI Source # 
Instance details

Defined in System.URI.File.Internal

Methods

(==) :: FileURI -> FileURI -> Bool #

(/=) :: FileURI -> FileURI -> Bool #

data ParseSyntax Source #

RFC syntax configuration.

Constructors

StrictPosix

Only parses the strict syntax according to section 2 of RFC 8089, which is technically posix paths.

ExtendedPosix

Also parses extended user information described in E.1

ExtendedWindows

Parses windows paths according to E.1, E.2 and E.3. Unlike the spec, posix paths are rejected.

Instances

Instances details
Show ParseSyntax Source # 
Instance details

Defined in System.URI.File.Internal

Eq ParseSyntax Source # 
Instance details

Defined in System.URI.File.Internal

Parsing

parseFileURI Source #

Arguments

:: ParseSyntax

RFC syntax configuration

-> ByteString

input file URI

-> Either String FileURI 

Parse a file URI such as file:///foo/bar into FileURI.

>>> parseFileURI StrictPosix "file:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "/path/to/file"})
>>> parseFileURI StrictPosix "file:///path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "/path/to/file"})
>>> parseFileURI StrictPosix "file://hostname/path/to/file"
Right (FileURI {fileAuth = Just "hostname", filePath = "/path/to/file"})
>>> parseFileURI StrictPosix "file://localhost/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "/path/to/file"})
>>> parseFileURI StrictPosix "http://localhost/path/to/file"
Left "string"
>>> parseFileURI StrictPosix "/path/to/file"
Left "string"
>>> parseFileURI ExtendedWindows "file://///host.example.com/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "//host.example.com/path/to/file"})
>>> parseFileURI ExtendedWindows "file:///c:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "c:/path/to/file"})
>>> parseFileURI ExtendedWindows "file:/c:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "c:/path/to/file"})
>>> parseFileURI ExtendedWindows "file:c:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "c:/path/to/file"})

Attoparsec parsers

fileURIStrictP :: Parser FileURI Source #

Parse a file URI according to the main ABNF in RFC 8089, without any extended rules, which is as follows:

   file-URI       = file-scheme ":" file-hier-part

   file-scheme    = "file"

   file-hier-part = ( "//" auth-path )
                  / local-path

   auth-path      = [ file-auth ] path-absolute

   local-path     = path-absolute

   file-auth      = "localhost"
                  / host

fileURIExtendedPosixP :: Parser FileURI Source #

Parse a file URI according to the main ABNF in RFC 8089, with extended rule E.1.

   file-URI       = file-scheme ":" file-hier-part

   file-scheme    = "file"

   file-hier-part = ( "//" auth-path )
                  / local-path

   auth-path      = [ file-auth ] path-absolute

   local-path     = path-absolute

   file-auth      = "localhost"
                  / [ userinfo "@" ] host

fileURIExtendedWindowsP :: Parser FileURI Source #

Parse a file URI according for windows according to E.1, E.2 and E.3. Unlike the spec, posix paths are rejected. The ABNF is a slight modification of Appendix F.

   file-URI       = file-scheme ":" file-hier-part

   file-scheme    = "file"

   file-hier-part = ( "//" auth-path )
                  / local-path

   auth-path      = [ file-auth ] file-absolute
                  / unc-authority path-absolute

   local-path     =  drive-letter path-absolute
                  / file-absolute

   file-auth      = "localhost"
                  / [ userinfo "@" ] host

   unc-authority  = 2*3"/" file-host

   file-host      = inline-IP  IPv4address  reg-name

   inline-IP      = "%5B" ( IPv6address / IPvFuture ) "%5D"

   file-absolute  = "/" drive-letter path-absolute

   drive-letter   = ALPHA ":"
                  / ALPHA "|"