content-entry
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -61,12 +61,2 @@ 'use strict'; | ||
const {Readable} = stream; | ||
var toReadableStream = input => ( | ||
new Readable({ | ||
read() { | ||
this.push(input); | ||
this.push(null); | ||
} | ||
}) | ||
); | ||
/** | ||
@@ -142,2 +132,12 @@ * brings Directory attributes to entries | ||
const {Readable} = stream; | ||
var toReadableStream = input => ( | ||
new Readable({ | ||
read() { | ||
this.push(input); | ||
this.push(null); | ||
} | ||
}) | ||
); | ||
/** | ||
@@ -270,142 +270,2 @@ * Content entries where a buffer is the primary data representation | ||
/** | ||
* Representation of one file or directory entry | ||
* All names are asolute (no leading '/') and build with '/' | ||
* @property {string} name file name inside of the repository | ||
* @property {string|Buffer|Stream} content | ||
* @property {string} type type of the content | ||
* @property {string} mode file permissions | ||
* @property {string} sha sha of the content | ||
* | ||
* @param {string} name file name inside of the repository | ||
* @param {string|Buffer|Stream} content | ||
* @param {string} type type of the content | ||
* @param {string} mode file permissions | ||
* @param {string} sha sha of the content | ||
*/ | ||
class Entry extends BaseEntry { | ||
static get TYPE_BLOB() { | ||
return "blob"; | ||
} | ||
static get TYPE_TREE() { | ||
return "tree"; | ||
} | ||
constructor( | ||
name, | ||
content = undefined, | ||
type = Entry.TYPE_BLOB, | ||
mode = "100644", | ||
sha | ||
) { | ||
super(name); | ||
Object.defineProperties(this, { | ||
content: { | ||
get() { | ||
return content; | ||
}, | ||
set(value) { | ||
content = value; | ||
} | ||
}, | ||
sha: { | ||
get() { | ||
return sha; | ||
}, | ||
set(value) { | ||
sha = value; | ||
} | ||
}, | ||
type: { value: type }, | ||
mode: { value: mode } | ||
}); | ||
} | ||
/** | ||
* Deliver content as string | ||
* @return {string} content | ||
*/ | ||
async getString() { | ||
if (typeof this.content === "string" || this.content instanceof String) { | ||
return this.content; | ||
} | ||
if (Buffer.isBuffer(this.content)) { | ||
return this.content.toString("utf8"); | ||
} | ||
return undefined; | ||
} | ||
async getBuffer() { | ||
if (Buffer.isBuffer(this.content)) { | ||
return this.content; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Deliver content as read stream | ||
* @return {ReadableStream} content | ||
*/ | ||
async getReadStream() { | ||
return this.content instanceof stream.Stream | ||
? this.content | ||
: toReadableStream(this.content); | ||
} | ||
toJSON() { | ||
return Object.assign( | ||
{ | ||
type: this.type, | ||
mode: this.mode, | ||
sha: this.sha | ||
}, | ||
super.toJSON() | ||
); | ||
} | ||
/** | ||
* compare meta info against other entry | ||
* @param {Entry} other | ||
* @return {boolean} true if other has the same meta information (name...) | ||
*/ | ||
async equalsMeta(other) { | ||
return ( | ||
other !== undefined && | ||
(this.name === other.name && | ||
this.type === other.type && | ||
this.mode === other.mode) | ||
); | ||
} | ||
/** | ||
* compare content against other entry | ||
* @param {Entry} other | ||
* @return {boolean} true if other has the same content (bitwise) | ||
*/ | ||
async equalsContent(other) { | ||
if (Buffer.isBuffer(this.content)) { | ||
if (Buffer.isBuffer(other.content)) { | ||
return this.content.equals(other.content); | ||
} | ||
} | ||
const [a, b] = await Promise.all([this.getString(), other.getString()]); | ||
return a === b; | ||
} | ||
/** | ||
* compare against other entry | ||
* @param {Entry} other | ||
* @return {boolean} true if other describes the same content | ||
*/ | ||
async equals(other) { | ||
return (await this.equalsMeta(other)) && (await this.equalsContent(other)); | ||
} | ||
} | ||
exports.BufferContentEntryMixin = BufferContentEntryMixin; | ||
@@ -418,2 +278,1 @@ exports.StreamContentEntryMixin = StreamContentEntryMixin; | ||
exports.EmptyContentEntry = EmptyContentEntry; | ||
exports.Entry = Entry; |
{ | ||
"name": "content-entry", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
100
README.md
@@ -24,100 +24,24 @@ [![npm](https://img.shields.io/npm/v/content-entry.svg)](https://www.npmjs.com/package/content-entry) | ||
- [Entry](#entry) | ||
- [BaseEntry](#baseentry) | ||
- [Parameters](#parameters) | ||
- [Properties](#properties) | ||
- [getString](#getstring) | ||
- [getReadStream](#getreadstream) | ||
- [equalsMeta](#equalsmeta) | ||
- [Parameters](#parameters-1) | ||
- [equalsContent](#equalscontent) | ||
- [Parameters](#parameters-2) | ||
- [equals](#equals) | ||
- [Parameters](#parameters-3) | ||
- [BaseEntry](#baseentry) | ||
- [Parameters](#parameters-4) | ||
- [Properties](#properties-1) | ||
- [getTypes](#gettypes) | ||
- [CollectionEntryMixin](#collectionentrymixin) | ||
- [Parameters](#parameters-5) | ||
- [Parameters](#parameters-1) | ||
- [EmptyContentEntry](#emptycontententry) | ||
- [ContentEntry](#contententry) | ||
- [equalsContent](#equalscontent-1) | ||
- [Parameters](#parameters-6) | ||
- [equalsContent](#equalscontent) | ||
- [Parameters](#parameters-2) | ||
- [BufferContentEntryMixin](#buffercontententrymixin) | ||
- [Parameters](#parameters-7) | ||
- [Properties](#properties-2) | ||
- [Parameters](#parameters-3) | ||
- [Properties](#properties-1) | ||
- [StreamContentEntryMixin](#streamcontententrymixin) | ||
- [Parameters](#parameters-8) | ||
- [Parameters](#parameters-4) | ||
- [StringContentEntryMixin](#stringcontententrymixin) | ||
- [Parameters](#parameters-9) | ||
- [Parameters](#parameters-5) | ||
- [Properties](#properties-2) | ||
- [StringContentEntry](#stringcontententry) | ||
- [Parameters](#parameters-6) | ||
- [Properties](#properties-3) | ||
- [StringContentEntry](#stringcontententry) | ||
- [Parameters](#parameters-10) | ||
- [Properties](#properties-4) | ||
## Entry | ||
**Extends BaseEntry** | ||
Representation of one file or directory entry | ||
All names are asolute (no leading '/') and build with '/' | ||
### Parameters | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file name inside of the repository | ||
- `content` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html) \| [Stream](https://nodejs.org/api/stream.html))** (optional, default `undefined`) | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** type of the content (optional, default `Entry.TYPE_BLOB`) | ||
- `mode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file permissions (optional, default `"100644"`) | ||
- `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sha of the content | ||
### Properties | ||
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file name inside of the repository | ||
- `content` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html) \| [Stream](https://nodejs.org/api/stream.html))** | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** type of the content | ||
- `mode` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** file permissions | ||
- `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sha of the content | ||
### getString | ||
Deliver content as string | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** content | ||
### getReadStream | ||
Deliver content as read stream | ||
Returns **ReadableStream** content | ||
### equalsMeta | ||
compare meta info against other entry | ||
#### Parameters | ||
- `other` **[Entry](#entry)** | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if other has the same meta information (name...) | ||
### equalsContent | ||
compare content against other entry | ||
#### Parameters | ||
- `other` **[Entry](#entry)** | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if other has the same content (bitwise) | ||
### equals | ||
compare against other entry | ||
#### Parameters | ||
- `other` **[Entry](#entry)** | ||
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if other describes the same content | ||
## BaseEntry | ||
@@ -166,3 +90,3 @@ | ||
- `other` **[Entry](#entry)** | ||
- `other` **Entry** | ||
@@ -169,0 +93,0 @@ Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if other has the same content (bitwise) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21127
492
140