Node-SMB / marsaud-smb2

SMB2 Client
53 stars 46 forks source link

feat: stat method and readdir with stats #66

Closed vdiez closed 3 years ago

vdiez commented 3 years ago

took the idea from https://github.com/Node-SMB/marsaud-smb2/issues/53#issuecomment-653601498

returns an object with the following structure:

{ CreationTime: 2020-07-21T04:52:14.186Z, LastAccessTime: 2020-08-05T13:39:15.848Z, LastWriteTime: 2020-07-21T04:52:14.186Z, ChangeTime: 2020-07-21T04:52:14.186Z, size: 1048576, isDirectory: [Function: isDirectory] }

Probably a good idea to standarize the return to a stats object (same as ssh2 package, but hard to map smb return response to it.

Full response:

{ StructureSize: <Buffer 59 00>, OplockLevel: <Buffer 00>, Flags: <Buffer 00>, CreateAction: <Buffer 01 00 00 00>, CreationTime: <Buffer be 2b e4 35 46 81 d6 01>, LastAccessTime: <Buffer fe c7 e4 35 46 81 d6 01>, LastWriteTime: <Buffer be 2b e4 35 46 81 d6 01>, ChangeTime: <Buffer be 2b e4 35 46 81 d6 01>, AllocationSize: <Buffer 00 00 00 00 00 00 00 00>, EndofFile: <Buffer 00 00 00 00 00 00 00 00>, FileAttributes: <Buffer 10 00 00 00>, Reserved2: <Buffer 00 00 00 00>, FileId: <Buffer ed cf 17 a3 00 00 00 00 b0 d4 a6 32 00 00 00 00>, CreateContextsOffset: <Buffer 00 00 00 00>, CreateContextsLength: <Buffer 00 00 00 00>, Buffer: }

julien-f commented 3 years ago

Hi, great!

Anyway you could add some tests for this?

vdiez commented 3 years ago

there you have them!

testing size and isDirectory() mainly

vdiez commented 3 years ago

should i merge both PR in this one? I'm thinking about creating a new tools/stats.js which generates a stat object from the file object we receive in the server response. And use birthtime, atime, mtime and ctime and instead of CreationTime, LastAccessTime, LastWriteTime and ChangeTime respectively to be more Node-standard

julien-f commented 3 years ago

@vdiez Do what you think is best and ping me when you need a review :slightly_smiling_face:

vdiez commented 3 years ago

done, i added all changes in this PR.

readdir now accepts an optional second parameter. If {stats: true} the response will include stats for each file

stats object has been made compatible with stats from fs module

vdiez commented 3 years ago

ok, everything looks good on my end. Please let me know if you need anything else.

Please I would appreciate a release next week if possible, I prefer not to depend on my repo for deployment.

Thanks!

vdiez commented 3 years ago

all commited, please let me know if all is as expected now.

julien-f commented 3 years ago

Published as 0.17.0

Your contributions are more than welcome, I'm not using this lib anymore, keep me posted if you want to help maintain it :slightly_smiling_face:

vdiez commented 3 years ago

Thanks Julien!

yeah, I can help maintain it if you need, I'm using it actively.

julien-f commented 3 years ago

Great, feel free to answer issues/PR and create PRs if you need something.

If that becomes necessary, I'll give you commit and/or publish rights :slightly_smiling_face: