1.0.7 • Published 8 years ago

sonic_differ v1.0.7

Weekly downloads
3
License
MIT
Repository
-
Last release
8 years ago

1、Introduction

This is the server part of Sonic Project.

2、Step

1)Node Version > 7.0

2)install sonic_differ module

npm install sonic_differ --save

3)import sonic_differ module

const sonic_differ = require('sonic_differ');

4)Intercept and process data from server in Sonic mode.

i)First, create a Sonic cache struct like following code.

let sonic = {
    buffer: [],
    write: function (chunk, encoding) {
        let buffer = chunk;
        let ecode = encoding || 'utf8';
        if (!Buffer.isBuffer(chunk)) {
            buffer = new Buffer(chunk, ecode);
        }
        sonic.buffer.push(buffer);
    }
};

ii)Second, Intercept the data from server and use sonic_differ module to process

response.on('data', (chunk, encoding) => {
    sonic.write(chunk, encoding)
});
response.on('end', () => {
    let result = differ(ctx, Buffer.concat(sonic.buffer));
    sonic.buffer = [];
    if (result.cache) {
        //304 Not Modified, return nothing.
        return ''
    } else {
        //other Sonic status.
        return result.data
    }
});
1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago