1 | import { Readable, Writable } from 'stream';
|
2 |
|
3 | interface ISMB2Options {
|
4 | share: string;
|
5 | username: string;
|
6 | domain: string;
|
7 | password: string;
|
8 | port?: number;
|
9 | packetConcurrency?: number;
|
10 | autoCloseTimeout?: number;
|
11 | debug?: boolean;
|
12 | }
|
13 |
|
14 | interface ICreateReadStreamOptions {
|
15 | autoClose?: boolean;
|
16 | end?: number;
|
17 | fd?: number;
|
18 | flags?: string;
|
19 | start?: number;
|
20 | }
|
21 |
|
22 | interface ICreateWriteStreamOptions {
|
23 | autoClose?: boolean;
|
24 | fd?: number;
|
25 | flags?: string;
|
26 | start?: number;
|
27 | }
|
28 |
|
29 | interface SMB2Readable extends Readable {
|
30 | fileSize: number;
|
31 | }
|
32 |
|
33 | interface SMB2Writable extends Writable {}
|
34 |
|
35 | interface IEncodingOption {
|
36 | encoding?: string | null;
|
37 | }
|
38 |
|
39 | interface IStatsOption {
|
40 | stats: true;
|
41 | }
|
42 |
|
43 | interface IStats {
|
44 | name: string,
|
45 | birthtime: Date,
|
46 | mtime: Date,
|
47 | atime: Date,
|
48 | ctime: Date,
|
49 | isDirectory(): boolean
|
50 | }
|
51 |
|
52 | interface IFileStats extends IStats {
|
53 | name: string,
|
54 | }
|
55 |
|
56 | declare class SMB2 {
|
57 | constructor(options: ISMB2Options);
|
58 | disconnect(): void;
|
59 | exists(path: string): Promise<boolean>;
|
60 | exists(path: string, cb: (err?: Error, exists?: boolean) => void): void;
|
61 |
|
62 | mkdir(path: string, mode?: number): Promise<void>;
|
63 | mkdir(path: string, mode: number, cb: (err?: Error) => void): void;
|
64 | mkdir(path: string, cb: (err?: Error) => void): void;
|
65 |
|
66 | readdir(path: string, options?: IEncodingOption): Promise<string[]>;
|
67 | readdir(path: string, options: IEncodingOption & IStatsOption): Promise<IFileStats[]>;
|
68 | readdir(path: string, cb: (err?: Error, files?: string[]) => void): void;
|
69 | readdir(path: string, options: IEncodingOption, cb: (err?: Error, files?: string[]) => void): void;
|
70 | readdir(path: string, options: IEncodingOption & IStatsOption, cb: (err?: Error, files?: IFileStats[]) => void): void;
|
71 |
|
72 | stat(path: string): Promise<IStats>;
|
73 | stat(path: string, cb: (err?: Error, stats?: IStats) => void): void;
|
74 |
|
75 | readFile(
|
76 | path: string,
|
77 | options?: { encoding?: null }
|
78 | ): Promise<Buffer>;
|
79 | readFile(
|
80 | path: string,
|
81 | options: { encoding: string }
|
82 | ): Promise<string>;
|
83 | readFile(
|
84 | path: string,
|
85 | cb: (err?: Error, content?: Buffer) => void
|
86 | ): void;
|
87 | readFile(
|
88 | path: string,
|
89 | options: { encoding?: null },
|
90 | cb: (err?: Error, content?: Buffer) => void
|
91 | ): void;
|
92 | readFile(
|
93 | path: string,
|
94 | options: { encoding: string },
|
95 | cb: (err?: Error, content?: string) => void
|
96 | ): void;
|
97 |
|
98 | rename(
|
99 | oldPath: string,
|
100 | newPath: string,
|
101 | options?: { replace: boolean }
|
102 | ): Promise<void>;
|
103 | rename(oldPath: string, newPath: string, cb: (err?: Error) => void): void;
|
104 | rename(
|
105 | oldPath: string,
|
106 | newPath: string,
|
107 | options: { replace: boolean },
|
108 | cb: (err?: Error) => void
|
109 | ): void;
|
110 |
|
111 | rmdir(path: string): Promise<void>;
|
112 | rmdir(path: string, cb: (err?: Error) => void): void;
|
113 |
|
114 | unlink(path: string): Promise<void>;
|
115 | unlink(path: string, cb: (err?: Error) => void): void;
|
116 |
|
117 | writeFile(
|
118 | path: string,
|
119 | data: string | Buffer,
|
120 | options?: IEncodingOption
|
121 | ): Promise<void>;
|
122 | writeFile(
|
123 | path: string,
|
124 | data: string | Buffer,
|
125 | cb: (err?: Error) => void
|
126 | ): void;
|
127 | writeFile(
|
128 | path: string,
|
129 | data: string | Buffer,
|
130 | options: IEncodingOption,
|
131 | cb: (err?: Error) => void
|
132 | ): void;
|
133 |
|
134 | truncate(path: string, length?: number): Promise<void>;
|
135 | truncate(path: string, length: number, cb: (err?: Error) => void): void;
|
136 |
|
137 | createReadStream(
|
138 | path: string,
|
139 | options?: ICreateReadStreamOptions
|
140 | ): Promise<SMB2Readable>;
|
141 | createReadStream(
|
142 | path: string,
|
143 | options: ICreateReadStreamOptions,
|
144 | cb: (err?: Error, readable?: SMB2Readable) => void
|
145 | ): void;
|
146 | createReadStream(
|
147 | path: string,
|
148 | cb: (err?: Error, readable?: SMB2Readable) => void
|
149 | ): void;
|
150 |
|
151 | createWriteStream(
|
152 | path: string,
|
153 | options?: ICreateWriteStreamOptions
|
154 | ): Promise<SMB2Writable>;
|
155 | createWriteStream(
|
156 | path: string,
|
157 | options: ICreateWriteStreamOptions,
|
158 | cb: (err?: Error, writable?: SMB2Writable) => void
|
159 | ): void;
|
160 | createWriteStream(
|
161 | path: string,
|
162 | cb: (err?: Error, writable?: SMB2Writable) => void
|
163 | ): void;
|
164 |
|
165 | open(
|
166 | path: string,
|
167 | flags: string,
|
168 | cb: (err?: Error, fd?: number) => void
|
169 | ): void;
|
170 | read(
|
171 | fd: number,
|
172 | buffer: Buffer,
|
173 | bufferOffset: number,
|
174 | toRead: number,
|
175 | fileOffset: number,
|
176 | cb: (err?: Error, read?: number, buffer?: Buffer) => void
|
177 | ): void;
|
178 | write(
|
179 | fd: number,
|
180 | buffer: Buffer,
|
181 | bufferOffset: number,
|
182 | toWrite: number,
|
183 | fileOffset: number,
|
184 | cb: (err?: Error, written?: number, buffer?: Buffer) => void
|
185 | ): void;
|
186 | close(fd: number, cb: (err?: Error) => void): void;
|
187 | }
|
188 |
|
189 | export default SMB2;
|