Skip to content

A bunch of stuff #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 11, 2015
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ language: node_js
sudo: false
node_js:
- 0.10
- 0.12
- 4.1
env:
- PATH=$HOME/purescript:$PATH
install:
Expand Down
30 changes: 0 additions & 30 deletions Gruntfile.js

This file was deleted.

5 changes: 5 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
"dependencies": {
"purescript-eff": "~0.1.0",
"purescript-maybe": "~0.3.1"
},
"devDependencies": {
"purescript-assert": "~0.1.1",
"purescript-console": "~0.1.1",
"purescript-foldable-traversable": "~0.4.1"
}
}
40 changes: 20 additions & 20 deletions docs/Node/Buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ An instance of Node's Buffer class.
instance showBuffer :: Show Buffer
```

#### `BufferWrite`
#### `BUFFER`

``` purescript
data BufferWrite :: !
data BUFFER :: !
```

Effect for buffer modification.
Effect for buffer creation, reading, or writing.

#### `BufferValueType`

Expand Down Expand Up @@ -68,23 +68,23 @@ instance showBufferValueType :: Show BufferValueType
#### `create`

``` purescript
create :: Int -> Buffer
create :: forall e. Int -> Eff (buffer :: BUFFER | e) Buffer
```

Creates a new buffer of the specified size.

#### `fromArray`

``` purescript
fromArray :: Array Octet -> Buffer
fromArray :: forall e. Array Octet -> Eff (buffer :: BUFFER | e) Buffer
```

Creates a new buffer from an array of octets, sized to match the array.

#### `fromString`

``` purescript
fromString :: String -> Encoding -> Buffer
fromString :: forall e. String -> Encoding -> Eff (buffer :: BUFFER | e) Buffer
```

Creates a new buffer from a string with the specified encoding, sized to
Expand All @@ -93,39 +93,39 @@ match the string.
#### `read`

``` purescript
read :: BufferValueType -> Offset -> Buffer -> Int
read :: forall e. BufferValueType -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) Int
```

Reads a numeric value from a buffer at the specified offset.

#### `readString`

``` purescript
readString :: Encoding -> Offset -> Offset -> Buffer -> String
readString :: forall e. Encoding -> Offset -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) String
```

Reads a section of a buffer as a string with the specified encoding.

#### `toString`

``` purescript
toString :: Encoding -> Buffer -> String
toString :: forall e. Encoding -> Buffer -> Eff (buffer :: BUFFER | e) String
```

Reads the buffer as a string with the specified encoding.

#### `write`

``` purescript
write :: forall e. BufferValueType -> Int -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e) Unit
write :: forall e. BufferValueType -> Int -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) Unit
```

Writes a numeric value to a buffer at the specified offset.

#### `writeString`

``` purescript
writeString :: forall e. Encoding -> Offset -> Int -> String -> Buffer -> Eff (buffer :: BufferWrite | e) Int
writeString :: forall e. Encoding -> Offset -> Int -> String -> Buffer -> Eff (buffer :: BUFFER | e) Int
```

Writes octets from a string to a buffer at the specified offset. Multi-byte
Expand All @@ -135,47 +135,47 @@ to write them fully. The number of bytes written is returned.
#### `toArray`

``` purescript
toArray :: Buffer -> Array Octet
toArray :: forall e. Buffer -> Eff (buffer :: BUFFER | e) (Array Octet)
```

Creates an array of octets from a buffer's contents.

#### `getAtOffset`

``` purescript
getAtOffset :: Offset -> Buffer -> Maybe Octet
getAtOffset :: forall e. Offset -> Buffer -> Eff (buffer :: BUFFER | e) (Maybe Octet)
```

Reads an octet from a buffer at the specified offset.

#### `setAtOffset`

``` purescript
setAtOffset :: forall e. Octet -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e) Unit
setAtOffset :: forall e. Octet -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) Unit
```

Writes an octet in the buffer at the specified offset.

#### `size`

``` purescript
size :: Buffer -> Int
size :: forall e. Buffer -> Eff (buffer :: BUFFER | e) Int
```

Returns the size of a buffer.

#### `concat`

``` purescript
concat :: Array Buffer -> Buffer
concat :: forall e. Array Buffer -> Eff (buffer :: BUFFER | e) Buffer
```

Concatenates a list of buffers.

#### `concat'`

``` purescript
concat' :: Array Buffer -> Int -> Buffer
concat' :: forall e. Array Buffer -> Int -> Eff (buffer :: BUFFER | e) Buffer
```

Concatenates a list of buffers, combining them into a new buffer of the
Expand All @@ -184,16 +184,16 @@ specified length.
#### `copy`

``` purescript
copy :: Offset -> Offset -> Buffer -> Offset -> Buffer -> Buffer
copy :: forall e. Offset -> Offset -> Buffer -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) Int
```

Copies a section of a source buffer into a target buffer at the specified
offset.
offset, and returns the number of octets copied.

#### `fill`

``` purescript
fill :: forall e. Octet -> Offset -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e) Unit
fill :: forall e. Octet -> Offset -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) Unit
```

Fills a range in a buffer with the specified octet.
Expand Down
73 changes: 50 additions & 23 deletions src/Node/Buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@
exports.showImpl = require('util').inspect;

exports.create = function (size) {
return new Buffer(size);
return function() {
return new Buffer(size);
};
};

exports.fromArray = function (octets) {
return new Buffer(octets);
return function() {
return new Buffer(octets);
};
};

exports.fromStringImpl = function (str) {
return function (encoding) {
return new Buffer(str, encoding);
return function() {
return new Buffer(str, encoding);
};
};
};

exports.readImpl = function (ty) {
return function (offset) {
return function (buf) {
return buf['read' + ty](offset);
return function() {
return buf['read' + ty](offset);
};
};
};
};
Expand All @@ -33,15 +41,19 @@ exports.readStringImpl = function (enc) {
return function (start) {
return function (end) {
return function (buff) {
return buff.toString(enc, start, end);
return function() {
return buff.toString(enc, start, end);
};
};
};
};
};

exports.toStringImpl = function (enc) {
return function (buff) {
return buff.toString(enc);
return function() {
return buff.toString(enc);
};
};
};

Expand Down Expand Up @@ -73,16 +85,21 @@ exports.writeStringImpl = function (enc) {
};

exports.toArray = function (buff) {
return buff.toJSON();
return function() {
var json = buff.toJSON()
return json.data || json;
};
};

exports.getAtOffsetImpl = function (nothing) {
return function (just) {
return function (buff) {
return function (offset) {
var octet = buff[offset];
return octet == null ? nothing
: just(buff[i]);
return function() {
var octet = buff[offset];
return octet == null ? nothing
: just(buff[i]);
};
};
};
};
Expand All @@ -91,25 +108,33 @@ exports.getAtOffsetImpl = function (nothing) {
exports.setAtOffset = function (value) {
return function (offset) {
return function (buff) {
buff[offset] = value;
return {};
return function() {
buff[offset] = value;
return {};
};
};
};
};

exports.size = function (buff) {
return buff.length;
return function() {
return buff.length;
};
};



exports.concat = function (buffs) {
return Buffer.concat(buffs);
return function() {
return Buffer.concat(buffs);
};
};

exports.concat$prime = function (buffs) {
exports["concat'"] = function (buffs) {
return function (totalLength) {
return Buffer.concat(buffs, totalLength);
return function() {
return Buffer.concat(buffs, totalLength);
};
};
};

Expand All @@ -118,21 +143,23 @@ exports.copy = function (srcStart) {
return function (src) {
return function (targStart) {
return function (targ) {
return src.copy(targ, targStart, srcStart, strcEnd);
return function() {
return src.copy(targ, targStart, srcStart, srcEnd);
};
};
};
};
};
};

exports.fill = function (buff) {
return function (octet) {
return function (start) {
return function (end) {
exports.fill = function (octet) {
return function (start) {
return function (end) {
return function (buf) {
return function() {
buff.fill(octet, start, end);
buf.fill(octet, start, end);
return {};
}
};
};
};
};
Expand Down
Loading