Comparing version 7.0.1 to 8.0.0-remove-bluebird-94c51dce0084a5241e5b8e0d04d8d02e795cf404
/// <reference types="node" /> | ||
import * as Bluebird from 'bluebird'; | ||
import { promises as fs } from 'fs'; | ||
import { Readable, Transform } from 'stream'; | ||
import { BufferDiskChunk, DiscardDiskChunk, DiskChunk } from './diskchunk'; | ||
import * as fs from './fs'; | ||
import { Interval } from './interval-intersection'; | ||
import { Range } from './mapped-ranges'; | ||
export { BufferDiskChunk, DiscardDiskChunk, DiskChunk, Interval, Range }; | ||
export { ReadResult, WriteResult } from './fs'; | ||
export interface ReadResult { | ||
bytesRead: number; | ||
buffer: Buffer; | ||
} | ||
export interface WriteResult { | ||
bytesWritten: number; | ||
buffer: Buffer; | ||
} | ||
export declare class DiskStream extends Readable { | ||
@@ -19,3 +25,3 @@ private readonly disk; | ||
} | ||
export declare function openFile(path: string, flags: string | number, mode?: number): Bluebird.Disposer<number>; | ||
export declare function withOpenFile<T>(path: string, flags: string | number, fn: (handle: fs.FileHandle) => Promise<T>): Promise<T>; | ||
export declare abstract class Disk { | ||
@@ -30,8 +36,8 @@ readOnly: boolean; | ||
protected abstract _getCapacity(): Promise<number>; | ||
protected abstract _read(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.ReadResult>; | ||
protected abstract _write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.WriteResult>; | ||
protected abstract _read(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<ReadResult>; | ||
protected abstract _write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<WriteResult>; | ||
protected abstract _flush(): Promise<void>; | ||
getTransformStream(): Transform; | ||
read(buffer: Buffer, _bufferOffset: number, length: number, fileOffset: number): Promise<fs.ReadResult>; | ||
write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.WriteResult>; | ||
read(buffer: Buffer, _bufferOffset: number, length: number, fileOffset: number): Promise<ReadResult>; | ||
write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<WriteResult>; | ||
flush(): Promise<void>; | ||
@@ -48,7 +54,7 @@ discard(offset: number, length: number): Promise<void>; | ||
export declare class FileDisk extends Disk { | ||
protected readonly fd: number; | ||
constructor(fd: number, readOnly?: boolean, recordWrites?: boolean, recordReads?: boolean, discardIsZero?: boolean); | ||
protected readonly handle: fs.FileHandle; | ||
constructor(handle: fs.FileHandle, readOnly?: boolean, recordWrites?: boolean, recordReads?: boolean, discardIsZero?: boolean); | ||
protected _getCapacity(): Promise<number>; | ||
protected _read(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.ReadResult>; | ||
protected _write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.WriteResult>; | ||
protected _read(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<ReadResult>; | ||
protected _write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<WriteResult>; | ||
protected _flush(): Promise<void>; | ||
@@ -60,5 +66,5 @@ } | ||
protected _getCapacity(): Promise<number>; | ||
protected _read(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.ReadResult>; | ||
protected _write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<fs.WriteResult>; | ||
protected _read(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<ReadResult>; | ||
protected _write(buffer: Buffer, bufferOffset: number, length: number, fileOffset: number): Promise<WriteResult>; | ||
protected _flush(): Promise<void>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BufferDisk = exports.FileDisk = exports.Disk = exports.openFile = exports.DiskStream = exports.DiskChunk = exports.DiscardDiskChunk = exports.BufferDiskChunk = void 0; | ||
const Bluebird = require("bluebird"); | ||
exports.BufferDisk = exports.FileDisk = exports.Disk = exports.withOpenFile = exports.DiskStream = exports.DiskChunk = exports.DiscardDiskChunk = exports.BufferDiskChunk = void 0; | ||
const fs_1 = require("fs"); | ||
const stream_1 = require("stream"); | ||
@@ -10,3 +10,2 @@ const diskchunk_1 = require("./diskchunk"); | ||
Object.defineProperty(exports, "DiskChunk", { enumerable: true, get: function () { return diskchunk_1.DiskChunk; } }); | ||
const fs = require("./fs"); | ||
const interval_intersection_1 = require("./interval-intersection"); | ||
@@ -99,14 +98,18 @@ const mapped_ranges_1 = require("./mapped-ranges"); | ||
} | ||
function openFile(path, flags, mode) { | ||
async function withOpenFile(path, flags, fn) { | ||
// Opens a file and closes it when you're done using it. | ||
// Arguments are the same that for `fs.open()` | ||
// Use it with Bluebird's `using`, example: | ||
// Bluebird.using(openFile('/some/path', 'r+'), (fd) => { | ||
// doSomething(fd); | ||
// Arguments are the same that for `fs.promises.open()` | ||
// Example: | ||
// await withOpenFile('/some/path', 'r+', async (handle) => { | ||
// doSomething(handle); | ||
// }); | ||
return fs.open(path, flags, mode).disposer((fd) => { | ||
return fs.close(fd); | ||
}); | ||
const handle = await fs_1.promises.open(path, flags); | ||
try { | ||
return await fn(handle); | ||
} | ||
finally { | ||
await handle.close(); | ||
} | ||
} | ||
exports.openFile = openFile; | ||
exports.withOpenFile = withOpenFile; | ||
class Disk { | ||
@@ -266,3 +269,3 @@ constructor(readOnly = false, recordWrites = false, recordReads = false, discardIsZero = true) { | ||
let offset = 0; | ||
await Bluebird.each(plan, async (entry) => { | ||
for (const entry of plan) { | ||
if (entry instanceof diskchunk_1.DiskChunk) { | ||
@@ -283,3 +286,3 @@ const data = entry.data(); | ||
} | ||
}); | ||
} | ||
return { bytesRead: offset, buffer }; | ||
@@ -290,18 +293,18 @@ } | ||
class FileDisk extends Disk { | ||
constructor(fd, readOnly = false, recordWrites = false, recordReads = false, discardIsZero = true) { | ||
constructor(handle, readOnly = false, recordWrites = false, recordReads = false, discardIsZero = true) { | ||
super(readOnly, recordWrites, recordReads, discardIsZero); | ||
this.fd = fd; | ||
this.handle = handle; | ||
} | ||
async _getCapacity() { | ||
const stats = await fs.fstat(this.fd); | ||
const stats = await this.handle.stat(); | ||
return stats.size; | ||
} | ||
async _read(buffer, bufferOffset, length, fileOffset) { | ||
return await fs.read(this.fd, buffer, bufferOffset, length, fileOffset); | ||
return await this.handle.read(buffer, bufferOffset, length, fileOffset); | ||
} | ||
async _write(buffer, bufferOffset, length, fileOffset) { | ||
return await fs.write(this.fd, buffer, bufferOffset, length, fileOffset); | ||
return await this.handle.write(buffer, bufferOffset, length, fileOffset); | ||
} | ||
async _flush() { | ||
await fs.fdatasync(this.fd); | ||
await this.handle.datasync(); | ||
} | ||
@@ -308,0 +311,0 @@ } |
@@ -7,2 +7,7 @@ # Change Log | ||
# v8.0.0 | ||
## (2020-07-27) | ||
* Stop using bluebird [Alexis Svinartchouk] | ||
# v7.0.1 | ||
@@ -9,0 +14,0 @@ ## (2020-07-24) |
{ | ||
"name": "file-disk", | ||
"version": "7.0.1", | ||
"version": "8.0.0-remove-bluebird-94c51dce0084a5241e5b8e0d04d8d02e795cf404", | ||
"description": "Handles reads / writes on disk image files.", | ||
@@ -36,5 +36,4 @@ "author": "Petros Angelatos <petrosagg@balena.io>", | ||
"@balena/lint": "^5.1.0", | ||
"@types/bluebird": "^3.5.32", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^6.14.10", | ||
"@types/node": "^10.17.28", | ||
"mocha": "^8.0.1", | ||
@@ -45,5 +44,4 @@ "ts-node": "^8.10.2", | ||
"dependencies": { | ||
"bluebird": "^3.7.2", | ||
"tslib": "^2.0.0" | ||
} | ||
} |
@@ -60,7 +60,6 @@ # file-disk | ||
const Bluebird = require('bluebird'); | ||
const filedisk = require('file-disk'); | ||
Bluebird.using(filedisk.openFile('/path/to/some/file', 'r+'), async (fd) => { | ||
const disk = new filedisk.FileDisk(fd) | ||
await filedisk.withOpenFile('/path/to/some/file', 'r+', async (handle) => { | ||
const disk = new filedisk.FileDisk(handle) | ||
@@ -86,3 +85,2 @@ // get file size | ||
const Bluebird = require('bluebird'); | ||
const filedisk = require('file-disk'); | ||
@@ -92,4 +90,4 @@ | ||
Bluebird.using(filedisk.openFile('/path/to/some/file', 'r'), async (fd) => { | ||
const disk = new filedisk.FileDisk(fd, true, true); | ||
await filedisk.withOpenFile('/path/to/some/file', 'r', async (handle) => { | ||
const disk = new filedisk.FileDisk(handle, true, true); | ||
let bytesRead, bytesWritten, buffer; | ||
@@ -108,3 +106,3 @@ | ||
// pipe the stream somewhere | ||
await new Bluebird((resolve, reject) => { | ||
await new Promise((resolve, reject) => { | ||
stream.pipe(someWritableStream) | ||
@@ -111,0 +109,0 @@ .on('close', resolve) |
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
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
1
6
58071
16
597
1
111
- Removedbluebird@^3.7.2
- Removedbluebird@3.7.2(transitive)