🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

virtual-file

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

virtual-file

[![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependency Status][david-image]][david-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][dow

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

virtual-file

NPM version Build status Test coverage Dependency Status License Downloads Gittip

A virtual file abstraction for. This is meant to be used as the file abstraction for normalize.

Goals:

  • Caching ideal for long running processes
  • Easily file transformations, including intermediary files
  • Seamless source map support
  • Suitable for production usage

Current limitations:

  • Files are considered to be on-disk. However, inline files (i.e. inlined <script>s) are currently not supported. Need to figure out a mechanism for those types of files.

API

var file = new File(uri)

Creates a new file abstraction based on a URI. A URI could have #s or ?s. However, the file must be a local file. If it's a remote file, download it first.

Properties

  • .filename - the filename of the file. Unlike the URI, this property is dynamic and removes any #s and ?s in the name.
  • .dirname - the folder this file is located.
  • .basename - the basename of this file. This property is dynamic, meaning you can set it, and the filename will be updated automatically.
  • .type - the current mime type of the file. Set the current mime type of the file to keep track of the current transformations.
  • .exists - whether the file exists, defaulting to true.
  • .sourcemap - whether source maps are enabled, defaulting to true.
  • .static - whether this file changes over time (i.e. for a watching instance), defaulting to false. Set this to true in production when you know files aren't going to change.

file.stat().then( => )

Check fs.stat() the file and get the sha256 sum of the file. Adds the following properties:

  • .length - the byte length of the file
  • .mtime - the modified time of the file as a Date.
  • .hash - the sha256 sum of the file as a Buffer.

You should run this before running anything else.

file.getString().then( string => )

Get the current contents of the file as a string. Also sets it as .string. If the string contains an inline source map, it will be removed and moved to .map.

file.string=

Set a string as the current contents of the file after a transformation. If the string contains an inline source map, it will be removed and moved to .map.

file.map

Get the current source map of the file, if any.

file.map=

Set the source map of the file. This should be set before file.string=. If a previous source map exists, it will be applied to the newest source map. Otherwise, the current string and .basename will be set as the source.

file.isStale().then( stale => )

Check whether the file is stale. If it is stale, then a new file object will be returned. Being using the new file object instead of this one. The file is stale if any of the following is true:

  • The file previously did not exist, but now does.
  • The file's length has changed.
  • The file's mtime has changed.
  • The sha256 sum of the file has changed.

FAQs

Package last updated on 05 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts