Adds explicit handling for 'file' URIs to the uri library.
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>
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 nilopen( [mode [, perm]] [, opt]) {|io| block } → objSee Kernel#open, URI::File#to_file_path
We require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This repository is subject to a Contributor Code of Conduct adapted from the Contributor Covenant, version 3.0, available at https://www.contributor-covenant.org/version/3/0/
This project is licensed under the ISC licence. See LICENSE for details
Copyright (c) 2019, Matthew Kerwin <matthew@kerwin.net.au> 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.