file-uri – the "file" URI scheme

Adds explicit handling for 'file' URIs to the uri library.

Build Status
Gem Version

Example

require 'uri'
require 'file-uri'

uri = URI.parse("file:///path/to/file.txt")
#=> #<URI::CoreFile file:/path/to/file.txt>

Also includes a Windows-specific version, which has extra handling for
drive letters at the start of paths.

require 'uri'
require 'file-uri/win'

uri = URI.parse("file:c:/windows/path.txt")
#=> #<URI::WinFile file:/c:/windows/path.txt>

uri + "/absolute/path.txt"
#=> #<URI::WinFile file:/c:/absolute/path.txt>

URI::File

local?( localhost: true )

Returns true if this file URI is local.

The localhost parameter instructs the library how to interpret
special values in the host field, to retain compatibility with various
other libraries and programs out there:

URI :any true false
"file://localhost/" local local non-local
"file://example.com/" local non-local non-local

to_unc( localhost: true )

Returns a UNC filespace selector string for this file URI.

Raises a RuntimeError if this is a local URI (see #local?)

to_file_path( localhost: true )

Returns a file path for this file URI.

Raises a RuntimeError if this is not a local URI (see #local?)

open( [mode [, perm]] [, opt]) → io or nil

open( [mode [, perm]] [, opt]) {|io| block } → obj

See Kernel#open, URI::File#to_file_path

Copyright (c) 2019, Matthew Kerwin 

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Contributor Covenant Code of Conduct

Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our
project and our community a harassment-free experience for everyone,
regardless of age, body size, disability, ethnicity, gender identity
and expression, level of experience, nationality, personal appearance,
race, religion, or sexual identity and orientation.

Our Standards

Examples of behavior that contributes to creating a positive
environment include:

Examples of unacceptable behavior by participants include:

Our Responsibilities

Project maintainers are responsible for clarifying the standards of
acceptable behavior and are expected to take appropriate and fair
corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit,
or reject comments, commits, code, wiki edits, issues, and other
contributions that are not aligned to this Code of Conduct, or to ban
temporarily or permanently any contributor for other behaviors that they
deem inappropriate, threatening, offensive, or harmful.

Scope

This Code of Conduct applies both within project spaces and in public
spaces when an individual is representing the project or its community.
Examples of representing a project or community include using an
official project e-mail address, posting via an official social media
account, or acting as an appointed representative at an online or
offline event. Representation of a project may be further defined and
clarified by project maintainers.

Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may
be reported by contacting the project team at matthew@kerwin.net.au.
All complaints will be reviewed and investigated and will result in a
response that is deemed necessary and appropriate to the circumstances.
The project team is obligated to maintain confidentiality with regard to
the reporter of an incident. Further details of specific enforcement
policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in
good faith may face temporary or permanent repercussions as determined
by other members of the project's leadership.

Attribution

This Code of Conduct is adapted from the Contributor Covenant,
version 1.4, available at http://contributor-covenant.org/version/1/4