ipfs-unixfs
Advanced tools
Comparing version 4.0.0 to 4.0.1-rc.0
@@ -1,12 +0,6 @@ | ||
export type Mtime = { | ||
secs: number; | ||
nsecs?: number | null | undefined; | ||
}; | ||
export type MtimeLike = { | ||
secs: number; | ||
nsecs?: number | undefined; | ||
} | { | ||
export type Mtime = import("./types").Mtime; | ||
export type MtimeLike = import("./types").Mtime | { | ||
Seconds: number; | ||
FractionalNanoseconds?: number | undefined; | ||
} | Mtime | [number, number] | Date | null | undefined; | ||
} | [number, number] | Date; | ||
declare class Data { | ||
@@ -35,3 +29,6 @@ /** | ||
fanout?: number | undefined; | ||
mtime?: MtimeLike | null; | ||
mtime?: import("./types").Mtime | { | ||
Seconds: number; | ||
FractionalNanoseconds?: number | undefined; | ||
} | [number, number] | Date | null | undefined; | ||
mode?: string | number | undefined; | ||
@@ -54,3 +51,3 @@ } | undefined); | ||
get mode(): number | undefined; | ||
mtime: Mtime | undefined; | ||
mtime: import("./types").Mtime | undefined; | ||
_mode: number | undefined; | ||
@@ -80,7 +77,6 @@ isDirectory(): boolean; | ||
/** | ||
* @param {MtimeLike} mtime | ||
* @returns {Mtime | undefined} | ||
* @param {any} input | ||
*/ | ||
export function parseMtime(mtime: MtimeLike): Mtime | undefined; | ||
export function parseMtime(input: any): import("./types").Mtime | undefined; | ||
export { Data as UnixFS }; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "ipfs-unixfs", | ||
"version": "4.0.0", | ||
"version": "4.0.1-rc.0+47f295b", | ||
"description": "JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)", | ||
@@ -34,4 +34,4 @@ "leadMaintainer": "Alex Potsides <alex.potsides@protocol.ai>", | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"npm": ">=4.0.0" | ||
"node": ">=14.0.0", | ||
"npm": ">=7.0.0" | ||
}, | ||
@@ -41,3 +41,3 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", | ||
"@types/mocha": "^8.2.1", | ||
"aegir": "^32.0.0", | ||
"aegir": "^32.1.0", | ||
"copy": "^0.3.2", | ||
@@ -62,3 +62,3 @@ "mkdirp": "^1.0.4", | ||
}, | ||
"gitHead": "172548bf5f5ecf2c6fd6f410be506ccd72804d28" | ||
"gitHead": "47f295bb9c274c16cfaa201831685d55567c18ac" | ||
} |
@@ -9,11 +9,6 @@ 'use strict' | ||
/** | ||
* @typedef {object} Mtime | ||
* @property {number} secs | ||
* @property {number | null} [nsecs] | ||
* @typedef {import('./types').Mtime} Mtime | ||
* @typedef {import('./types').MtimeLike} MtimeLike | ||
*/ | ||
/** | ||
* @typedef {null | undefined | { secs: number, nsecs?: number} | { Seconds: number, FractionalNanoseconds?: number} | Mtime | [number, number] | Date} MtimeLike | ||
*/ | ||
const types = [ | ||
@@ -44,25 +39,33 @@ 'raw', | ||
if (typeof mode === 'string') { | ||
mode = parseInt(mode, 8) | ||
if (typeof mode === 'number') { | ||
return mode & 0xFFF | ||
} | ||
return mode & 0xFFF | ||
mode = mode.toString() | ||
if (mode.substring(0, 1) === '0') { | ||
// octal string | ||
return parseInt(mode, 8) & 0xFFF | ||
} | ||
// decimal string | ||
return parseInt(mode, 10) & 0xFFF | ||
} | ||
/** | ||
* @param {MtimeLike} mtime | ||
* @returns {Mtime | undefined} | ||
* @param {any} input | ||
*/ | ||
function parseMtime (mtime) { | ||
if (mtime == null) { | ||
function parseMtime (input) { | ||
if (input == null) { | ||
return undefined | ||
} | ||
/** @type {Mtime | undefined} */ | ||
let mtime | ||
// { secs, nsecs } | ||
if (Object.prototype.hasOwnProperty.call(mtime, 'secs')) { | ||
if (input.secs != null) { | ||
mtime = { | ||
// @ts-ignore | ||
secs: mtime.secs, | ||
// @ts-ignore | ||
nsecs: mtime.nsecs | ||
secs: input.secs, | ||
nsecs: input.nsecs | ||
} | ||
@@ -72,9 +75,6 @@ } | ||
// UnixFS TimeSpec | ||
if (Object.prototype.hasOwnProperty.call(mtime, 'Seconds')) { | ||
// @ts-ignore | ||
if (input.Seconds != null) { | ||
mtime = { | ||
// @ts-ignore | ||
secs: mtime.Seconds, | ||
// @ts-ignore | ||
nsecs: mtime.FractionalNanoseconds | ||
secs: input.Seconds, | ||
nsecs: input.FractionalNanoseconds | ||
} | ||
@@ -84,6 +84,6 @@ } | ||
// process.hrtime() | ||
if (Array.isArray(mtime)) { | ||
if (Array.isArray(input)) { | ||
mtime = { | ||
secs: mtime[0], | ||
nsecs: mtime[1] | ||
secs: input[0], | ||
nsecs: input[1] | ||
} | ||
@@ -93,4 +93,4 @@ } | ||
// Javascript Date | ||
if (mtime instanceof Date) { | ||
const ms = mtime.getTime() | ||
if (input instanceof Date) { | ||
const ms = input.getTime() | ||
const secs = Math.floor(ms / 1000) | ||
@@ -108,9 +108,9 @@ | ||
// process.hrtime.bigint() | ||
if (typeof mtime === 'bigint') { | ||
const secs = mtime / BigInt(1e9) | ||
const nsecs = mtime - (secs * BigInt(1e9)) | ||
if (input instanceof BigInt) { | ||
const secs = input / BigInt(1e9) | ||
const nsecs = input - (secs * BigInt(1e9)) | ||
mtime = { | ||
secs: parseInt(secs), | ||
nsecs: parseInt(nsecs) | ||
secs: parseInt(secs.toString()), | ||
nsecs: parseInt(nsecs.toString()) | ||
} | ||
@@ -124,8 +124,6 @@ } | ||
// @ts-ignore | ||
if (mtime.nsecs < 0 || mtime.nsecs > 999999999) { | ||
if (mtime != null && mtime.nsecs != null && (mtime.nsecs < 0 || mtime.nsecs > 999999999)) { | ||
throw errcode(new Error('mtime-nsecs must be within the range [0,999999999]'), 'ERR_INVALID_MTIME_NSECS') | ||
} | ||
// @ts-ignore | ||
return mtime | ||
@@ -132,0 +130,0 @@ } |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
64887
13
1425
1
1