Skip to content

Commit

Permalink
first version on github for older version see the gitlab repos here h…
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-sakemaer committed Sep 14, 2016
0 parents commit 4a6a7bb
Show file tree
Hide file tree
Showing 25 changed files with 2,196 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .analysis_options
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Supported lint rules and documentation: http://dart-lang.github.io/linter/lints/
linter:
rules:
- always_declare_return_types
- always_specify_types
- annotate_overrides
# - avoid_as
- avoid_init_to_null
- avoid_empty_else
- avoid_return_types_on_setters
- await_only_futures
- camel_case_types
- comment_references
- constant_identifier_names
- control_flow_in_finally
- empty_constructor_bodies
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- non_constant_identifier_names
- one_member_abstracts
# - overridden_fields
- package_api_docs
- package_prefixed_library_names
- prefer_is_not_empty
# - public_member_api_docs
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- super_goes_last
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- type_init_formals
- unnecessary_brace_in_string_interp
- unnecessary_getters_setters
- unrelated_type_equality_checks
- package_names

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Files and directories created by pub
.packages
.pub/
build/
packages
pubspec.lock

# Files created by dart2js
*.dart.js
*.part.js
*.js.deps
*.js.map
*.info.json

# Directory created by dartdoc
doc/api/

# JetBrains IDEs
.idea/
*.iml
*.ipr
*.iws

# Atom
.atom
7 changes: 7 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Below is a list of people and organizations that have contributed
# to the nodejs.dart project. Names should be added to the list like so:
#
# Name/Organization <email address>

GrimShield
Kevin Segaud <[email protected]>
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## 0.0.1

**Warning:** This is the first commit.

This commit include a wrap of the class listed below:
- all `Readable`
- all `Writable`
- all `Duplex`
- all `File System` excluding `FSWatcher`
- all `Process`
- all `Child Process`
- all `Module`
- part of `Buffer`
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2016, GrimShield.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of GrimShield nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL GrimShield BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# nodejs.dart

nodejs.dart is a wrapper of the nodejs API in dart

## Warning

This is under development so if you have suggestion on the existing API or you find a bug don't hesitate to fill an issue :)
50 changes: 50 additions & 0 deletions lib/nodejs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2016, GrimShield. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

@JS()
library nodejs;

import "dart:async";
import "dart:convert";
import "dart:typed_data";

import "package:js/js.dart";

part "src/utils.dart";
part "src/object.dart";
part "src/module.dart";

part "src/util.dart";

part "src/buffer.dart";

part "src/errors/error.dart";
part "src/errors/range_error.dart";

part "src/events.dart";

part "src/stream.dart";
part "src/stream/readable.dart";
part "src/stream/writable.dart";
part "src/stream/duplex.dart";

part "src/process.dart";

part "src/child_process.dart";

part "src/fs.dart";

@JS('nodejs.filename')
external String get filename;

@JS('nodejs.dirname')
external String get dirname;

@JS('nodejs.require')
external dynamic require(String id);

@JS('JSON.stringify')
external String stringify(NativeJsObject object);

@JS('JSON.parse')
external NativeJsObject parse(String json);
123 changes: 123 additions & 0 deletions lib/src/buffer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright (c) 2016, GrimShield. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of nodejs;

@JS('setObjectValueAtIndex')
external void _setObjectValueAtIndex(dynamic object, int index, dynamic value);
@JS('getObjectValueAtIndex')
external void _getObjectValueAtIndex(dynamic object, int index);

@JS('Buffer.compare')
external int _bufferCompare(NativeJsBuffer buffer1, NativeJsBuffer buffer2);

@JS('Buffer')
class NativeJsBuffer {
external static NativeJsBuffer from(dynamic arg1,
[dynamic arg2, dynamic arg3]);
external static NativeJsBuffer alloc(int size,
[dynamic fill, String encoding]);
external static NativeJsBuffer allocUnsafe(int size);

external static int byteLength(dynamic object, String encoding);
external static NativeJsBuffer concat(List<NativeJsBuffer> buffers,
[int totalLength]);
external static bool isBuffer(dynamic object);
external static bool isEncoding(String encoding);

external int compare(NativeJsBuffer otherBuffer);
external int copy(NativeJsBuffer targetBuffer,
[int targetStart, int sourceStart, int sourceEnd]);
external Iterator<dynamic> entries();

external int get length;

@override
external String toString([String encoding = 'utf8', int start = 0, int end]);
}

class BufferEncoding {
static const String ascii = 'ascii';
static const String utf8 = 'utf8';
static const String utf16le = 'utf16le';
static const String binary = 'binary';
static const String hex = 'hex';
}

class Buffer {
NativeJsBuffer _buffer;

Buffer.alloc(int size, [dynamic fill = null, String encoding = 'utf8']) {
_buffer = NativeJsBuffer.alloc(size, fill, encoding);
}

Buffer.allocUnsafe(int size) {
_buffer = NativeJsBuffer.allocUnsafe(size);
}

Buffer.fromList(List<num> list) {
_buffer = NativeJsBuffer.from(list);
}

Buffer.fromArrayBuffer(ByteBuffer byteBuffer,
[int byteOffset = 0, int length]) {
if (length == null) length = byteBuffer.lengthInBytes - byteOffset;
_buffer = NativeJsBuffer.from(byteBuffer);
}

Buffer.fromBuffer(Buffer buffer) {
_buffer = NativeJsBuffer.from(buffer._buffer);
}

Buffer.fromStringWithEncoding(String str, [String encoding = 'utf8']) {
_buffer = NativeJsBuffer.from(str, encoding);
}

Buffer.FromNativeJsBuffer(this._buffer);

static int byteLength(dynamic object, [String encoding = 'utf8']) =>
NativeJsBuffer.byteLength(object, encoding);
static int compareTwoBuffer(Buffer buffer1, Buffer buffer2) =>
_bufferCompare(buffer1._buffer, buffer2._buffer);
static Buffer concat(List<Buffer> buffers, [int totalLength]) {
List<NativeJsBuffer> jsBuffers =
buffers.map((Buffer buffer) => buffer._buffer);
return new Buffer.FromNativeJsBuffer(
NativeJsBuffer.concat(jsBuffers, totalLength));
}

static bool isBuffer(dynamic object) => NativeJsBuffer.isBuffer(object);
static bool isEncoding(String encoding) =>
NativeJsBuffer.isEncoding(encoding);

void operator []=(int index, dynamic value) {
_setObjectValueAtIndex(_buffer, index, value);
}

dynamic operator [](int index) {
return _getObjectValueAtIndex(_buffer, index);
}

int compare(Buffer otherBuffer) => _buffer.compare(otherBuffer._buffer);

int copy(Buffer targetBuffer,
[int targetStart = 0, int sourceStart = 0, int sourceEnd]) {
if (sourceEnd == null) sourceEnd = length;
return _buffer.copy(
targetBuffer._buffer, targetStart, sourceStart, sourceEnd);
}

Iterable<dynamic> entries() sync* {
for (int i = 0; i < length; i++) {
yield <num>[i, this[i]];
}
}

int get length => _buffer.length;

@override
String toString([String encoding = 'utf8', int start = 0, int end]) {
if (end == null) end = _buffer.length;
return _buffer.toString(encoding, start, end);
}
}
Loading

0 comments on commit 4a6a7bb

Please sign in to comment.