Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: allow WHATWG URL and file: URLs as paths #10739

Closed
wants to merge 1 commit into from

Commits on Feb 6, 2017

  1. fs: allow WHATWG URL and file: URLs as paths

    Updates the fs module APIs to allow 'file://' URL objects
    to be passed as the path.
    
    For example:
    
    ```js
    const URL = require('url').URL;
    const myURL = new URL('file:///C:/path/to/file');
    fs.readFile(myURL, (err, data) => {});
    ```
    
    On Windows, file: URLs with a hostname convert to UNC paths,
    while file: URLs with drive letters convert to local absolute
    paths:
    
    ```
    file://hostname/a/b/c => \\hostname\a\b\c
    file:///c:/a/b/c => c:\a\b\c
    ```
    
    On all other platforms, file: URLs with a hostname are unsupported
    and will result in a throw:
    
    ```
    file://hostname/a/b/c => throw!
    file:///a/b/c => /a/b/c
    ```
    
    The documentation for the fs API is intentionally not updated in
    this commit because the URL API is still considered experimental
    and is not officially documented *at this time*
    
    Note that file: URLs are *required* by spec to always be absolute
    paths from the file system root.
    
    This is a semver-major commit because it changes error handling
    on the fs APIs.
    
    Refs: nodejs#10703
    jasnell committed Feb 6, 2017
    Configuration menu
    Copy the full SHA
    d0a8c1b View commit details
    Browse the repository at this point in the history