Home

Awesome

file-pointer is a object wrapper to handle files.

Installation

$ npm install file-pointer

Essence

file-pointer is meant to provide an object wrapper around files and folders for easier manipulation and handling. It does this by creating a number of non-enumberable properties that provide easy access to various manipulations with the underlying file.

Usage

These are various examples of using the file-pointer library

	var fp = require('file-pointer');

	// Basic
	var obj = fp.define('./node_modules'); // returns Pointer

	fp.define('./node_modules', function (err, obj) {
		// Obj is a Folder, since the stats were mapped and it was determined to be one
	});

	// Direct calls

	var file = new fp.File('./index.js');
	var folder = new fp.Folder('./node_modules');
	var pointer = new fp.Pointer('./test');

	// use the previously created pointer to create a File
	var testFile = new fp.File({pointer: pointer});

	// Create a Folder by defining opts.type
	var syncFolder = fp.define({filePath: './node_modules, type:'directory'});

Added properties

The main objective of file-pointer is to add convenience methods to the objects for easy usage. These are either values or functions. All values are preceeded by a single underscore and all functions with two underscores.

Pointer

The following properties are added to Pointer object and since File and Folder inherit from Pointer then they are accessible on all types.

None of these properties are enumerable and only _type is configurable. This means that:

	var fp = require('file-pointer');

	var p = new fp.Pointer('./node_modules');

	console.log(p); // Will log an apparently empty object {}
	console.log(p._name); // node_modules
	p._name = 'test';
	console.log(p._name); // node_modules

File

These properties are added to the Pointer object properties.

Folder

These properties are added to the Pointer object properties.

Public API

The file-pointer will expose the following methods of interest.

define(opts, [callback])

Function for creating a file-pointer object

opts - can be either string or object with the following properties

callback - if defined then fs.stat function is used to determine the type of the object

License

The MIT License (MIT) Copyright (c) 2012 Karl Düüna

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.