Commit 6ff85d62 authored by Fabrice Marsaud's avatar Fabrice Marsaud

getSize and a various fixes

parent ff41b97a
# http://EditorConfig.org
#
# Julien Fontanet's configuration
# https://gist.github.com/julien-f/8096213
# Top-most EditorConfig file.
root = true
# Common config.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespaces = true
# CoffeeScript
#
# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md
[*.{,lit}coffee]
indent_size = 2
indent_style = space
# Markdown
[*.{md,mdwn,mdown,markdown}]
indent_size = 4
indent_style = space
# Package.json
#
# This indentation style is the one used by npm.
[/package.json]
indent_size = 2
indent_style = space
# Jade
[*.jade]
indent_size = 2
indent_style = space
# JavaScript
#
# Two spaces seems to be the standard most common style, at least in
# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces).
[*.js]
indent_size = 2
indent_style = space
# Less
[*.less]
indent_size = 2
indent_style = space
# Sass
#
# Style used for http://libsass.com
[*.s[ac]ss]
indent_size = 2
indent_style = space
# YAML
#
# Only spaces are allowed.
[*.yaml]
indent_size = 2
indent_style = space
......@@ -29,7 +29,7 @@ class SmbReadableStream extends Readable {
return
}
const rest = this.offset.sub(this.fileLength).neg()
const packetSize = Math.min(maxPacketSize, rest.toNumber/*, size*/)
const packetSize = Math.min(maxPacketSize, rest.toNumber()/*, size*/)
const offset = new Bigint(this.offset)
this.wait = true
......@@ -43,7 +43,6 @@ class SmbReadableStream extends Readable {
if (this.encoding) {
content = content.toString(this.encoding)
}
this.offset = this.offset.add(packetSize)
// size -= packetSize
if (!this.push(content)) {
......@@ -51,19 +50,22 @@ class SmbReadableStream extends Readable {
}
}
if (this.offset.ge(this.fileLength)) {
await requestAsync('close', this.file, this.connection)
this.push(null)
await requestAsync('close', this.file, this.connection)
}
}
}
export default function (path, options, cb) {
if(typeof options == 'function'){
cb = options;
options = {};
if (typeof options === 'function') {
cb = options
options = {}
}
request('open', {path}, this, (err, file) => {
if (err) {
if (err.code === 'STATUS_OBJECT_NAME_NOT_FOUND') {
err.code = 'ENOENT'
}
cb(err)
} else {
cb(null, new SmbReadableStream(this, file, options))
......
......@@ -17,11 +17,10 @@ class SmbWritableStream extends Writable {
}
async _write (chunk, encoding, next) {
const count = this.count++
encoding = this.encoding || encoding
chunk = Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk, encoding)
while(chunk.length > 0) {
while (chunk.length > 0) {
const packetSize = Math.min(maxPacketSize.toNumber(), chunk.length)
const packet = chunk.slice(0, packetSize)
chunk = chunk.slice(packetSize)
......@@ -47,9 +46,9 @@ class SmbWritableStream extends Writable {
}
export default function (path, options, cb) {
if(typeof options == 'function'){
cb = options;
options = {};
if (typeof options === 'function') {
cb = options
options = {}
}
request('create', {path}, this, (err, file) => {
if (err) {
......
......@@ -24,7 +24,7 @@ export default async function (path, cb) {
const structure = path.split('\\')
const base = []
try {
while(structure.length) {
while (structure.length) {
base.push(structure.shift())
const basePath = base.join('\\')
if (!basePath.length) {
......
import {request} from '../tools/smb2-forge'
export default function (path, cb) {
request('open', {path}, this, (err, file) => {
if (err) {
if (err.code === 'STATUS_OBJECT_NAME_NOT_FOUND') {
err.code = 'ENOENT'
}
cb(err)
} else {
let fileLength = 0
for (let i = 0; i < file.EndofFile.length; i++) {
fileLength |= file.EndofFile[i] << (i * 8)
}
cb(null, fileLength)
}
})
}
......@@ -98,5 +98,4 @@ proto.rmdir = SMB2Connection.requireConnect(require('./api/rmdir'));
proto.mkdir = SMB2Connection.requireConnect(require('./api/mkdir'));
proto.ensureDir = SMB2Connection.requireConnect(require('./api/ensureDir'));
proto.getSize = SMB2Connection.requireConnect(require('./api/getSize'));
......@@ -38,7 +38,8 @@
"babel": "^5.8.34",
"babel-eslint": "^4.1.6",
"babel-runtime": "^5.8.34",
"source-map-support": "^0.4.0"
"source-map-support": "^0.4.0",
"standard": "^5.4.1"
},
"standard": {
"parser": "babel-eslint"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment