Add fs.split

This commit is contained in:
Corey Johnson
2012-07-03 14:44:41 -07:00
parent 33813d0c42
commit fc660c2790
2 changed files with 14 additions and 0 deletions

View File

@@ -41,6 +41,11 @@ describe "fs", ->
expect(fs.join('/a/b/', 'c', 'd')).toBe '/a/b/c/d'
expect(fs.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/'
describe ".split(path)", ->
it "returns path components", ->
expect(fs.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"]
expect(fs.split("a/b/c.txt")).toEqual ["a", "b", "c.txt"]
describe ".extension(path)", ->
it "returns the extension of a file", ->
expect(fs.extension("a/b/corey.txt")).toBe '.txt'

View File

@@ -77,6 +77,15 @@ module.exports =
read: (path) ->
$native.read(path)
# Returns an array of path components. If the path is absolute, the first
# component will be an indicator of the root of the file system; for file
# systems with drives (such as Windows), this is the drive identifier with a
# colon, like "c:"; on Unix, this is an empty string "". The intent is that
# calling "join.apply" with the result of "split" as arguments will
# reconstruct the path.
split: (path) ->
path.split("/")
# Open, write, flush, and close a file, writing the given content.
write: (path, content) ->
$native.write(path, content)