Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Apr 10, 2018
0 parents commit b504268
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
@@ -0,0 +1,19 @@
# Created by .ignore support plugin (hsz.mobi)
### git template
.idea

~ci.list.txt
~ci.log.txt
~ci.errors.txt

*.stackdump
*.bak
*.old

package-lock.json

test/**/*.js
test/**/*.d.ts
test/*.js
test/*.d.ts
test/temp
21 changes: 21 additions & 0 deletions .npmignore
@@ -0,0 +1,21 @@
# Created by .ignore support plugin (hsz.mobi)
### npm template
.idea

~ci.list.txt
~ci.log.txt
~ci.errors.txt

*.stackdump
*.bak
*.old

tsconfig.json
#package-lock.json

test

.github
.gitkeep

/.*
22 changes: 22 additions & 0 deletions fs.d.ts
@@ -0,0 +1,22 @@
/// <reference types="node" />
/**
* Created by user on 2018/4/10/010.
*/
import * as fs from "fs";
import { IOptionsStreamPipe, IPipe } from './index';
export declare type IOptionsFsCreateReadStream = {
flags?: string;
encoding?: string;
fd?: number;
mode?: number;
autoClose?: boolean;
start?: number;
end?: number;
highWaterMark?: number;
};
export declare class ReadStream extends fs.ReadStream {
pipe<T extends NodeJS.WritableStream>(destination: T, options?: IOptionsStreamPipe): IPipe<this, T>;
static createReadStream(file: string | Buffer, options?: IOptionsFsCreateReadStream, ...argv: any[]): ReadStream & fs.ReadStream;
}
export declare const createReadStream: typeof ReadStream.createReadStream;
export default createReadStream;
19 changes: 19 additions & 0 deletions fs.js
@@ -0,0 +1,19 @@
"use strict";
/**
* Created by user on 2018/4/10/010.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const index_1 = require("./index");
class ReadStream extends fs.ReadStream {
pipe(destination, options) {
return index_1.pipe(this, destination, options);
}
static createReadStream(file, options, ...argv) {
// @ts-ignore
return new this(file, options, ...argv);
}
}
exports.ReadStream = ReadStream;
exports.createReadStream = ReadStream.createReadStream.bind(ReadStream);
exports.default = exports.createReadStream;
37 changes: 37 additions & 0 deletions fs.ts
@@ -0,0 +1,37 @@
/**
* Created by user on 2018/4/10/010.
*/

import * as fs from "fs";
import * as stream from "stream";

import { IOptionsStreamPipe, pipe, IPipe } from './index';

export type IOptionsFsCreateReadStream = {
flags?: string;
encoding?: string;
fd?: number;
mode?: number;
autoClose?: boolean;
start?: number;
end?: number;
highWaterMark?: number;
};

export class ReadStream extends fs.ReadStream
{
pipe<T extends NodeJS.WritableStream>(destination: T, options?: IOptionsStreamPipe): IPipe<this, T>
{
return pipe(this, destination, options) as IPipe<this, T>;
}

static createReadStream(file: string | Buffer, options?: IOptionsFsCreateReadStream, ...argv): ReadStream & fs.ReadStream
{
// @ts-ignore
return new this(file, options, ...argv);
}
}

export const createReadStream = ReadStream.createReadStream.bind(ReadStream) as typeof ReadStream.createReadStream;

export default createReadStream;
15 changes: 15 additions & 0 deletions index.d.ts
@@ -0,0 +1,15 @@
/// <reference types="node" />
/**
* Created by user on 2018/4/10/010.
*/
export declare type IOptionsStreamPipe = {
end?: boolean;
};
export declare type IPipe<U extends NodeJS.ReadableStream, T extends NodeJS.WritableStream> = T & {
pipFrom: U;
};
export declare function pipe<U extends NodeJS.ReadableStream, T extends NodeJS.WritableStream>(srcStream: U, destStream: T, options?: IOptionsStreamPipe): T & {
pipFrom?: U;
};
import * as self from './index';
export default self;
13 changes: 13 additions & 0 deletions index.js
@@ -0,0 +1,13 @@
"use strict";
/**
* Created by user on 2018/4/10/010.
*/
Object.defineProperty(exports, "__esModule", { value: true });
function pipe(srcStream, destStream, options) {
let _dest = destStream;
_dest.pipFrom = srcStream;
return srcStream.pipe(_dest);
}
exports.pipe = pipe;
const self = require("./index");
exports.default = self;
25 changes: 25 additions & 0 deletions index.ts
@@ -0,0 +1,25 @@
/**
* Created by user on 2018/4/10/010.
*/

export type IOptionsStreamPipe = {
end?: boolean;
}

export type IPipe<U extends NodeJS.ReadableStream, T extends NodeJS.WritableStream> = T & {
pipFrom: U,
};

export function pipe<U extends NodeJS.ReadableStream, T extends NodeJS.WritableStream>(srcStream: U, destStream: T, options?: IOptionsStreamPipe)
{
let _dest = destStream as T & {
pipFrom?: U,
};

_dest.pipFrom = srcStream;

return srcStream.pipe(_dest);
}

import * as self from './index';
export default self;
23 changes: 23 additions & 0 deletions package.json
@@ -0,0 +1,23 @@
{
"name": "stream-pipe",
"version": "1.0.0",
"description": "",
"homepage": "https://github.com/bluelovers/node-stream-pipe#readme",
"bugs": {
"url": "https://github.com/bluelovers/node-stream-pipe/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bluelovers/node-stream-pipe.git"
},
"license": "ISC",
"author": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^9.6.2"
}
}
43 changes: 43 additions & 0 deletions tsconfig.json
@@ -0,0 +1,43 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "es2017",

"moduleResolution": "node",
"allowJs": false,

//"sourceMap": true,
//"inlineSourceMap": true,
//"inlineSources": true,

"declaration": true,
"experimentalDecorators": true,

"allowSyntheticDefaultImports": true,

"strict": false,

//"forceConsistentCasingInFileNames": true,

"locale": "zh-TW",
"pretty": true,

// "removeComments": true,

// "baseUrl": ".",
// "sourceRoot": ".",
// "rootDir": ".",
// "outDir": ".",

// "paths": {
//
// },

"traceResolution": true,
"newLine": "lf"
},

"exclude": [
"node_modules"
]
}

0 comments on commit b504268

Please sign in to comment.