Skip to content

Commit f5aac21

Browse files
committed
Merge remote-tracking branch 'origin/master' into volume-opendir
2 parents 7506bf0 + c9d7497 commit f5aac21

File tree

10 files changed

+69
-37
lines changed

10 files changed

+69
-37
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# [4.10.0](https://github.com/streamich/memfs/compare/v4.9.4...v4.10.0) (2024-07-27)
2+
3+
4+
### Features
5+
6+
* 🎸 add IReadableWebStreamOptions type ([99ebd64](https://github.com/streamich/memfs/commit/99ebd6491e4886dc9947d5b3c867241b7158357a))
7+
* 🎸 implement FileHandle.readableWebStream() ([c3ddc6c](https://github.com/streamich/memfs/commit/c3ddc6c21ea112056ee84e3c131f09f5b2582779))
8+
9+
## [4.9.4](https://github.com/streamich/memfs/compare/v4.9.3...v4.9.4) (2024-07-23)
10+
11+
12+
### Bug Fixes
13+
14+
* ensure files in subdirectories are returned as buffers when calling `toJSON` with `asBuffer` ([#1041](https://github.com/streamich/memfs/issues/1041)) ([c3d4cf3](https://github.com/streamich/memfs/commit/c3d4cf36e438f7fef2dab4639c08449ceada28a3))
15+
116
## [4.9.3](https://github.com/streamich/memfs/compare/v4.9.2...v4.9.3) (2024-06-14)
217

318

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "memfs",
3-
"version": "4.9.3",
3+
"version": "4.10.0",
44
"description": "In-memory file-system with Node's fs API.",
55
"keywords": [
66
"fs",
@@ -125,7 +125,7 @@
125125
},
126126
"dependencies": {
127127
"@jsonjoy.com/json-pack": "^1.0.3",
128-
"@jsonjoy.com/util": "^1.1.2",
128+
"@jsonjoy.com/util": "^1.3.0",
129129
"tree-dump": "^1.0.1",
130130
"tslib": "^2.0.0"
131131
},

src/__tests__/volume.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ describe('volume', () => {
197197
const result = vol.toJSON('/', {}, false, true)['/file'];
198198
expect(result).toStrictEqual(buffer);
199199
});
200+
201+
it('Outputs files in subdirectories as buffers too', () => {
202+
const buffer = Buffer.from('Hello');
203+
const vol = new Volume();
204+
vol.mkdirSync('/dir');
205+
vol.writeFileSync('/dir/file', buffer);
206+
const result = vol.toJSON('/', {}, false, true)['/dir/file'];
207+
expect(result).toStrictEqual(buffer);
208+
});
200209
});
201210

202211
describe('.fromJSON(json[, cwd])', () => {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fromStream } from '@jsonjoy.com/util/lib/streams/fromStream';
2+
import { createFs } from '../util';
3+
4+
describe('FileHandle', () => {
5+
describe('.readableWebStream()', () => {
6+
it('can read contest of a file', async () => {
7+
const fs = createFs();
8+
fs.writeFileSync('/foo', 'bar');
9+
const handle = await fs.promises.open('/foo', 'r');
10+
const stream = handle.readableWebStream();
11+
expect(stream).toBeInstanceOf(ReadableStream);
12+
const data = fromStream(stream);
13+
expect(await data).toEqual(Buffer.from('bar'));
14+
});
15+
});
16+
});

src/fsa-to-node/json.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
import { CborEncoder } from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder';
2-
import { CborDecoder } from '@jsonjoy.com/json-pack/lib/cbor/CborDecoder';
3-
4-
export const encoder = new CborEncoder();
5-
export const decoder = new CborDecoder();
1+
import { encoder, decoder } from '@jsonjoy.com/json-pack/lib/cbor/shared';
2+
export { encoder, decoder };

src/node/FileHandle.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ export class FileHandle implements IFileHandle {
3333
return promisify(this.fs, 'fdatasync')(this.fd);
3434
}
3535

36+
readableWebStream(options?: opts.IReadableWebStreamOptions): ReadableStream {
37+
return new ReadableStream({
38+
pull: async controller => {
39+
const data = await this.readFile();
40+
controller.enqueue(data);
41+
controller.close();
42+
},
43+
});
44+
}
45+
3646
read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult> {
3747
return promisify(this.fs, 'read', bytesRead => ({ bytesRead, buffer }))(this.fd, buffer, offset, length, position);
3848
}

src/node/types/misc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { EventEmitter } from 'events';
44
import type { TSetTimeout } from '../../setTimeoutUnref';
55
import type {
66
IAppendFileOptions,
7+
IReadableWebStreamOptions,
78
IReadFileOptions,
8-
IReadStreamOptions,
99
IStatOptions,
1010
IWriteFileOptions,
1111
} from './options';
@@ -129,6 +129,7 @@ export interface IFileHandle {
129129
chown(uid: number, gid: number): Promise<void>;
130130
close(): Promise<void>;
131131
datasync(): Promise<void>;
132+
readableWebStream(options?: IReadableWebStreamOptions): ReadableStream;
132133
read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
133134
readv(buffers: ArrayBufferView[], position?: number | null): Promise<TFileHandleReadvResult>;
134135
readFile(options?: IReadFileOptions | string): Promise<TDataOut>;

src/node/types/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export interface IFStatOptions {
3232

3333
export interface IAppendFileOptions extends IFileOptions {}
3434

35+
export interface IReadableWebStreamOptions {
36+
type?: 'bytes' | undefined;
37+
}
38+
3539
export interface IReaddirOptions extends IOptions {
3640
recursive?: boolean;
3741
withFileTypes?: boolean;

src/volume.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {
557557
if (path) filename = relative(path, filename);
558558
json[filename] = asBuffer ? node.getBuffer() : node.getString();
559559
} else if (node.isDirectory()) {
560-
this._toJSON(child, json, path);
560+
this._toJSON(child, json, path, asBuffer);
561561
}
562562
}
563563

yarn.lock

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@
616616
resolved "https://registry.yarnpkg.com/@jsonjoy.com/util/-/util-1.2.0.tgz#0fe9a92de72308c566ebcebe8b5a3f01d3149df2"
617617
integrity sha512-4B8B+3vFsY4eo33DMKyJPlQ3sBMpPFUZK2dr3O3rXrOGKKbYG44J0XSFkDo1VOQiri5HFEhIeVvItjR2xcazmg==
618618

619+
"@jsonjoy.com/util@^1.3.0":
620+
version "1.3.0"
621+
resolved "https://registry.yarnpkg.com/@jsonjoy.com/util/-/util-1.3.0.tgz#e5623885bb5e0c48c1151e4dae422fb03a5887a1"
622+
integrity sha512-Cebt4Vk7k1xHy87kHY7KSPLT77A7Ev7IfOblyLZhtYEhrdQ6fX4EoLq3xOQ3O/DRMEh2ok5nyC180E+ABS8Wmw==
623+
619624
"@leichtgewicht/ip-codec@^2.0.1":
620625
version "2.0.5"
621626
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz#4fc56c15c580b9adb7dc3c333a134e540b44bfb1"
@@ -6837,16 +6842,7 @@ string-length@^4.0.1:
68376842
char-regex "^1.0.2"
68386843
strip-ansi "^6.0.0"
68396844

6840-
"string-width-cjs@npm:string-width@^4.2.0":
6841-
version "4.2.3"
6842-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
6843-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
6844-
dependencies:
6845-
emoji-regex "^8.0.0"
6846-
is-fullwidth-code-point "^3.0.0"
6847-
strip-ansi "^6.0.1"
6848-
6849-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
6845+
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
68506846
version "4.2.3"
68516847
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
68526848
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6906,14 +6902,7 @@ string_decoder@~1.1.1:
69066902
dependencies:
69076903
safe-buffer "~5.1.0"
69086904

6909-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
6910-
version "6.0.1"
6911-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
6912-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
6913-
dependencies:
6914-
ansi-regex "^5.0.1"
6915-
6916-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6905+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
69176906
version "6.0.1"
69186907
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
69196908
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -7740,16 +7729,7 @@ wordwrap@^1.0.0:
77407729
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
77417730
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
77427731

7743-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
7744-
version "7.0.0"
7745-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
7746-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
7747-
dependencies:
7748-
ansi-styles "^4.0.0"
7749-
string-width "^4.1.0"
7750-
strip-ansi "^6.0.0"
7751-
7752-
wrap-ansi@^7.0.0:
7732+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
77537733
version "7.0.0"
77547734
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
77557735
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)