output-file-sync

WebJar for output-file-sync

Лицензия

Лицензия

ISC
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

output-file-sync
Последняя версия

Последняя версия

2.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

output-file-sync
WebJar for output-file-sync
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/shinnn/output-file-sync

Скачать output-file-sync

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/output-file-sync/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>output-file-sync</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/output-file-sync/
implementation 'org.webjars.npm:output-file-sync:2.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/output-file-sync/
implementation ("org.webjars.npm:output-file-sync:2.0.1")
'org.webjars.npm:output-file-sync:jar:2.0.1'
<dependency org="org.webjars.npm" name="output-file-sync" rev="2.0.1">
  <artifact name="output-file-sync" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='output-file-sync', version='2.0.1')
)
libraryDependencies += "org.webjars.npm" % "output-file-sync" % "2.0.1"
[org.webjars.npm/output-file-sync "2.0.1"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
org.webjars.npm : graceful-fs jar [4.1.11,5)
org.webjars.npm : is-plain-obj jar [1.1.0,2)
org.webjars.npm : mkdirp jar [0.5.1,0.6)

Модули Проекта

Данный проект не имеет модулей.

output-file-sync

npm version Build Status Coverage Status

Synchronously write a file and create its ancestor directories if needed

import {readFileSync} from 'fs';
import outputFileSync from 'output-file-sync';

outputFileSync('foo/bar/baz.txt', 'Hi!');
readFileSync('foo/bar/baz.txt', 'utf8'); //=> 'Hi!'

Difference from fs.outputFileSync

This module is very similar to fs-extra's fs.outputFileSync method, but different in the following points:

  1. output-file-sync returns the path of the directory created first. See the API document for more details.
  2. output-file-sync accepts mkdirp options.
    import {statSync} from 'fs';
    import outputFileSync from 'output-file-sync';
    
    outputFileSync('foo/bar', 'content', {mode: 33260});
    statSync('foo').mode; //=> 33260
  3. output-file-sync validates its arguments strictly, and prints highly informative error message.

Installation

Use npm.

npm install output-file-sync

API

import outputFileSync from 'output-file-sync';

outputFileSync(path, data [, options])

path: string
data: string, Buffer or Uint8Array
options: Object (options for fs.writeFileSync and mkdirp) or string (encoding)
Return: string if it creates more than one directories, otherwise null

It writes the data to a file synchronously. If ancestor directories of the file don't exist, it creates the directories before writing the file.

import {statSync} from 'fs';
import outputFileSync from 'output-file-sync';

// When the directory `foo/bar` exists
outputFileSync('foo/bar/baz/qux.txt', 'Hello', 'utf-8');

statSync('foo/bar/baz').isDirectory(); //=> true
statSync('foo/bar/baz/qux.txt').isFile(); //=> true

It returns the directory path just like mkdirp.sync does:

Returns the first directory that had to be created, if any.

const dir = outputFileSync('foo/bar/baz.txt', 'Hello');
dir === path.resolve('foo'); //=> true

options

All options for fs.writeFileSync and mkdirp are available.

Additionally, you can pass fileMode and dirMode options to set different permission between the file and directories.

options.fileMode

Set the mode of a file, overriding mode option.

options.dirMode

Set the modes of directories, overriding mode option.

outputFileSync('dir/file', 'content', {dirMode: '0745', fileMode: '0644'});
fs.statSync('dir').mode.toString(8); //=> '40745'
fs.statSync('dir/file').mode.toString(8); //=> '100644'

Related

License

ISC License © 2017 - 2019 Watanabe Shinnosuke

Версии библиотеки

Версия
2.0.1
1.1.2
1.1.0