mirror of
https://scm.univ-tours.fr/22107988t/rappaurio-sae501_502.git
synced 2025-08-29 17:55:58 +02:00
permet l'ajout des frameworks et des routes
This commit is contained in:
51
app/node_modules/hyntax/lib/stream-tokenizer.js
generated
vendored
Normal file
51
app/node_modules/hyntax/lib/stream-tokenizer.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
const { Transform } = require('stream')
|
||||
|
||||
const tokenize = require('./tokenize')
|
||||
|
||||
class StreamTokenizer extends Transform {
|
||||
constructor (options) {
|
||||
super(Object.assign(
|
||||
{},
|
||||
options,
|
||||
{
|
||||
decodeStrings: false,
|
||||
readableObjectMode: true
|
||||
}
|
||||
))
|
||||
|
||||
this.currentTokenizerState = undefined
|
||||
this.setDefaultEncoding('utf8')
|
||||
}
|
||||
|
||||
_transform (chunk, encoding, callback) {
|
||||
let chunkString = chunk
|
||||
|
||||
if (Buffer.isBuffer(chunk)) {
|
||||
chunkString = chunk.toString()
|
||||
}
|
||||
|
||||
const { state, tokens } = tokenize(
|
||||
chunkString,
|
||||
this.currentTokenizerState,
|
||||
{ isFinalChunk: false }
|
||||
)
|
||||
|
||||
this.currentTokenizerState = state
|
||||
|
||||
callback(null, tokens)
|
||||
}
|
||||
|
||||
_flush (callback) {
|
||||
const tokenizeResults = tokenize(
|
||||
'',
|
||||
this.currentTokenizerState,
|
||||
{ isFinalChunk: true }
|
||||
)
|
||||
|
||||
this.push(tokenizeResults.tokens)
|
||||
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StreamTokenizer
|
Reference in New Issue
Block a user