New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

abstract-file

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-file - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

17

lib/attributes.js

@@ -88,2 +88,8 @@ (function() {

stat: null,
_contents: {
assigned: false
},
encoding: {
type: 'String'
},
contents: {

@@ -104,2 +110,13 @@ assign: function(value, dest, src, name) {

return value;
},
set: function(value) {
return this._contents = value;
},
get: function() {
var result;
result = this._contents;
if (result && this.encoding && isBuffer(result)) {
result = result.toString(this.encoding);
}
return result;
}

@@ -106,0 +123,0 @@ },

89

lib/index.js

@@ -115,3 +115,3 @@ (function() {

AbstractFile.prototype.isText = function() {
return isString(this.contents);
return !!this.encoding;
};

@@ -156,3 +156,3 @@

}
return this.hasOwnProperty('contents') && (this.contents != null) && this.validate(aOptions, false);
return this.hasOwnProperty('contents') && (this._contents != null) && this.validate(aOptions, false);
};

@@ -185,4 +185,14 @@

_this._loadContent(aOptions, function(err, result) {
var vEncoding;
if (!err) {
_this.contents = result;
if (aOptions.encoding || aOptions.text) {
vEncoding = aOptions.encoding;
if (vEncoding == null) {
vEncoding = 'utf8';
}
_this.encoding = vEncoding;
} else {
_this.encoding = null;
}
_this._contents = result;
if (_this.skipSize !== aOptions.skipSize) {

@@ -219,3 +229,3 @@ _this.skipSize = aOptions.skipSize;

AbstractFile.prototype.loadSync = function(aOptions) {
var checkValid;
var checkValid, vEncoding;
if (isFunction(this._loadStatSync)) {

@@ -235,3 +245,12 @@ aOptions = this.getOptions(aOptions);

}
return this.contents = this._loadContentSync(aOptions);
if (aOptions.encoding || aOptions.text) {
vEncoding = aOptions.encoding;
if (vEncoding == null) {
vEncoding = 'utf8';
}
this.encoding = vEncoding;
} else {
this.encoding = null;
}
return this._contents = this._loadContentSync(aOptions);
} else {

@@ -338,6 +357,3 @@

if (!aOptions.reload && this.loaded(aOptions)) {
result = this.contents;
if (aOptions.text && !isString(result)) {
result = result.toString();
}
result = this._contents;
if (aOptions.overwrite !== false) {

@@ -352,4 +368,14 @@ if (this.skipSize !== aOptions.skipSize) {

return function(err, result) {
var vEncoding;
if (!(err || aOptions.overwrite === false)) {
_this.contents = result;
if (aOptions.encoding || aOptions.text) {
vEncoding = aOptions.encoding;
if (vEncoding == null) {
vEncoding = 'utf8';
}
_this.encoding = vEncoding;
} else {
_this.encoding = null;
}
_this._contents = result;
if (_this.skipSize !== aOptions.skipSize) {

@@ -367,3 +393,3 @@ _this.skipSize = aOptions.skipSize;

AbstractFile.prototype.loadContentSync = function(aOptions) {
var result;
var result, vEncoding;
if (isFunction(this._loadContentSync)) {

@@ -374,5 +400,2 @@ aOptions = this.getOptions(aOptions);

result = this.contents;
if (aOptions.text && !isString(result)) {
result = result.toString();
}
} else {

@@ -382,6 +405,15 @@ result = this._loadContentSync(aOptions);

if (aOptions.overwrite !== false) {
if (aOptions.encoding || aOptions.text) {
vEncoding = aOptions.encoding;
if (vEncoding == null) {
vEncoding = 'utf8';
}
this.encoding = vEncoding;
} else {
this.encoding = null;
}
if (this.skipSize !== aOptions.skipSize) {
this.skipSize = aOptions.skipSize;
}
this.contents = result;
this._contents = result;
}

@@ -425,3 +457,3 @@ } else {

AbstractFile.prototype.getContentSync = function(aOptions) {
var result;
var result, vEncoding;
if (!isObject(aOptions)) {

@@ -435,4 +467,12 @@ aOptions = {};

result = this.loadContentSync(aOptions);
if (aOptions.skipSize > 0 && isFunction(result.slice)) {
result = result.slice(aOptions.skipSize);
if (result) {
if (aOptions.text && !isString(result)) {
if (aOptions.encoding) {
vEncoding = aOptions.encoding;
}
result = result.toString(vEncoding);
}
if (aOptions.skipSize > 0 && isFunction(result.slice)) {
result = result.slice(aOptions.skipSize);
}
}

@@ -454,4 +494,13 @@ return result;

return this.loadContent(aOptions, function(err, result) {
if (result && aOptions.skipSize > 0 && isFunction(result.slice)) {
result = result.slice(aOptions.skipSize);
var vEncoding;
if (result) {
if (aOptions.text && !isString(result)) {
if (aOptions.encoding) {
vEncoding = aOptions.encoding;
}
result = result.toString(vEncoding);
}
if (aOptions.skipSize > 0 && isFunction(result.slice)) {
result = result.slice(aOptions.skipSize);
}
}

@@ -458,0 +507,0 @@ return done(err, result);

{
"name": "abstract-file",
"description": "It can be used on any virtual file system, and stream supports.",
"version": "0.4.2",
"version": "0.4.3",
"homepage": "https://github.com/snowyu/abstract-file.js",

@@ -6,0 +6,0 @@ "repository": {

@@ -87,4 +87,2 @@ ## abstract-file [![npm](https://img.shields.io/npm/v/abstract-file.svg)](https://npmjs.org/package/abstract-file)

* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true.
* `text` *(Boolean)*: whether load file contents as text, defaults to false.
only available for `buffer` is true.
* `reload` *(Boolean)*: whether force to reload the contents from the file. defaults to false.

@@ -95,4 +93,2 @@ * `overwrite` *(Boolean)*: whether assign to this.contents after loading the contents from the file. defaults to true.

* `buffer` *(Boolean)*: whether load file contents as buffer or stream, defaults to true.
* `text` *(Boolean)*: whether load file contents as text, defaults to false.
only available for `buffer` is true.
* `reload` *(Boolean)*: whether force to reload the contents from the file. defaults to false.

@@ -103,5 +99,7 @@ * `overwrite` *(Boolean)*: whether assign to this.contents after loading the contents from the file. defaults to true.

only available for File(not for folder)
* `text` *(Boolean)*: whether load file contents as text, defaults to false.
* `done` *Function(err, content)*: the callback function.
* `getContentSync(aOptions)`: Synchronous get the file contents buffer, skipSize used.
only available for File(not for folder)
* `text` *(Boolean)*: whether load file contents as text, defaults to false.
* `loadStat(aOptions, done)`: Asynchronous load file stats.

@@ -133,2 +131,13 @@ * `done` *Function(err, stat)*: the callback function.

### v0.4
+ with new property-manager v0.10.0
+ base object(prototypeOf) supports
* add overwrite option to getContent/getContentSync
* [bug] getContent should get loaded content as the buffer when text is false.
+ `encoding` *(String)* attribute if the contents is a text.
+ `_contents` *(Buffer|Stream)* internal attribute
* change the `contents` attribute to a dynamic attirbute.
* **broken** the loadContent return the `_contents`(Buffer|Stream) now.
### v0.3

@@ -135,0 +144,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc