0.2.3 • Published 7 years ago

simple-async-fs v0.2.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

simple-async-fs

Simple & async middleware for the node fs package

Warning: This is pre-release software. Don't use in production!

Code example

Files

printInfo.ts

import { Directory, File } from "simple-async-fs"

export default async function printInfo(item: Directory | File){
    // Print directory or file info
    console.log(`Path: ${item.path}\n`)
    console.log(`Name: ${item.name}\n`)
    console.log(`Type: ${item.type}\n\n`)

    if(item.type == "Directory"){
        // Print all the children
        const dir = item as Directory
        let items = (await dir.children).map(item => `  - ${item.name} (${item.type})`)
        console.log(`Children:\n${items.join("\n")}`)
    }
}

example1.ts

import FileSystem, { Directory, File } from "simple-async-fs"
import printInfo from "./printInfo"

// Get current directory
const currentDir = FileSystem.currentDir

// Get parent directory
const parentDir = currentDir.parent

// The parent can be null if there's no parent directory (C:/ does not have any parent directory)
if(parentDir != null) printInfo(parentDir)

example2.ts

import FileSystem, { Directory, File } from "simple-async-fs"
import printInfo from "./printInfo"

(async() => {
    const file = await FileSystem.getItem(`C:/Users/Someone/Documents/test.docx`)
    if(file != null) printInfo(file)
})()

Output

example1.ts

Path: C:/Users/Someone/Documents
Name: Documents
Type: Directory

Children:
  - test.docx (File)
  - CloudStorage (Directory)
  - test.txt (File)

example2.ts

Path: C:/Users/Someone/Documents/test.docx
Name: test.docx
Type: File
0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.7

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago