File URL Conversion
NodeJS
Hard
3 views
Problem Description
Convert a file path to file URL and back, print both.
Input Format
stdin: file path.
Output Format
Print two lines.
Sample Test Case
Output:
file:///C:/tmp/a.txt\
C:\\\ mp\\\\a.txt
Constraints
Use url module helpers.
Official Solution
const fs = require('fs');
const { pathToFileURL, fileURLToPath } = require('url');
const p = fs.readFileSync(0, 'utf8').trim();
if (!p) process.exit(0);
const u = pathToFileURL(p).toString();
const back = fileURLToPath(u);
console.log(u);
console.log(back);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!