Socket
Socket
Sign inDemoInstall

vinyl

Package Overview
Dependencies
1
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vinyl

A virtual file format


Version published
Weekly downloads
4.8M
decreased by-5.09%
Maintainers
1
Created
Weekly downloads
 

Package description

What is vinyl?

The vinyl npm package is a virtual file format used in Node.js streams. It is commonly used in build systems like Gulp to represent files, allowing for easy manipulation and transformation of file contents and metadata.

What are vinyl's main functionalities?

Creating a Vinyl File

This feature allows you to create a new Vinyl file object. The code sample demonstrates how to create a Vinyl file with a specified current working directory, base path, file path, and contents.

const Vinyl = require('vinyl');
const file = new Vinyl({
  cwd: "/",
  base: "/test/",
  path: "/test/file.js",
  contents: Buffer.from("console.log('Hello, world!');")
});
console.log(file);

Reading File Contents

This feature allows you to read the contents of a Vinyl file. The code sample demonstrates how to create a Vinyl file and then read its contents as a string.

const Vinyl = require('vinyl');
const file = new Vinyl({
  cwd: "/",
  base: "/test/",
  path: "/test/file.js",
  contents: Buffer.from("console.log('Hello, world!');")
});
console.log(file.contents.toString());

Checking File Properties

This feature allows you to check various properties of a Vinyl file, such as whether its contents are a buffer, a stream, or null. The code sample demonstrates how to create a Vinyl file and check these properties.

const Vinyl = require('vinyl');
const file = new Vinyl({
  cwd: "/",
  base: "/test/",
  path: "/test/file.js",
  contents: Buffer.from("console.log('Hello, world!');")
});
console.log(file.isBuffer());
console.log(file.isStream());
console.log(file.isNull());

Other packages similar to vinyl

Readme

Source

Build Status

NPM version

Information

Packagevinyl
DescriptionA virtual file format
Node Version>= 0.9

File

var File = require('vinyl');

var coffeeFile = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
  contents: new Buffer("test = 123")
});

constructor(options)

options.cwd

Type: String
Default: process.cwd()

options.base

Used for relative pathing. Typically where a glob starts.

Type: String
Default: options.cwd

options.path

Full path to the file.

Type: String
Default: null

options.stat

The result of an fs.stat call. See fs.Stats for more information.

Type: fs.Stats
Default: null

options.contents

File contents.

Type: Buffer, Stream, or null
Default: null

isBuffer()

Returns true if file.contents is a Buffer.

isStream()

Returns true if file.contents is a Stream.

isNull()

Returns true if file.contents is null.

clone()

Returns a new File object with all attributes cloned.

pipe(stream)

If file.contents is a Buffer, it will write it to the stream.

If file.contents is a Stream, it will pipe it to the stream.

If file.contents is null, it will do nothing.

Returns the stream.

inspect()

Returns a pretty String interpretation of the File. Useful for console.log.

relative

Returns path.relative for the file base and file path.

Example:

var file = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
});

console.log(file.relative); // file.coffee

LICENSE

(MIT License)

Copyright (c) 2013 Fractal contact@wearefractal.com

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.

FAQs

Last updated on 24 Dec 2013

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc