forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
111
node_modules/level-transcoder/lib/formats.js
generated
vendored
Normal file
111
node_modules/level-transcoder/lib/formats.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
'use strict'
|
||||
|
||||
const { Buffer } = require('buffer') || {}
|
||||
const { Encoding } = require('./encoding')
|
||||
const textEndec = require('./text-endec')
|
||||
|
||||
/**
|
||||
* @template TIn, TOut
|
||||
* @extends {Encoding<TIn,Buffer,TOut>}
|
||||
*/
|
||||
class BufferFormat extends Encoding {
|
||||
/**
|
||||
* @param {Omit<IEncoding<TIn, Buffer, TOut>, 'format'>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
super({ ...options, format: 'buffer' })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createViewTranscoder () {
|
||||
return new ViewFormat({
|
||||
encode: this.encode, // Buffer is a view (UInt8Array)
|
||||
decode: (data) => this.decode(
|
||||
Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
),
|
||||
name: `${this.name}+view`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createBufferTranscoder () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @extends {Encoding<TIn,Uint8Array,TOut>}
|
||||
* @template TIn, TOut
|
||||
*/
|
||||
class ViewFormat extends Encoding {
|
||||
/**
|
||||
* @param {Omit<IEncoding<TIn, Uint8Array, TOut>, 'format'>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
super({ ...options, format: 'view' })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createBufferTranscoder () {
|
||||
return new BufferFormat({
|
||||
encode: (data) => {
|
||||
const view = this.encode(data)
|
||||
return Buffer.from(view.buffer, view.byteOffset, view.byteLength)
|
||||
},
|
||||
decode: this.decode, // Buffer is a view (UInt8Array)
|
||||
name: `${this.name}+buffer`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createViewTranscoder () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @extends {Encoding<TIn,string,TOut>}
|
||||
* @template TIn, TOut
|
||||
*/
|
||||
class UTF8Format extends Encoding {
|
||||
/**
|
||||
* @param {Omit<IEncoding<TIn, string, TOut>, 'format'>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
super({ ...options, format: 'utf8' })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createBufferTranscoder () {
|
||||
return new BufferFormat({
|
||||
encode: (data) => Buffer.from(this.encode(data), 'utf8'),
|
||||
decode: (data) => this.decode(data.toString('utf8')),
|
||||
name: `${this.name}+buffer`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createViewTranscoder () {
|
||||
const { textEncoder, textDecoder } = textEndec()
|
||||
|
||||
return new ViewFormat({
|
||||
encode: (data) => textEncoder.encode(this.encode(data)),
|
||||
decode: (data) => this.decode(textDecoder.decode(data)),
|
||||
name: `${this.name}+view`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createUTF8Transcoder () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
exports.BufferFormat = BufferFormat
|
||||
exports.ViewFormat = ViewFormat
|
||||
exports.UTF8Format = UTF8Format
|
||||
|
||||
/**
|
||||
* @typedef {import('./encoding').IEncoding<TIn,TFormat,TOut>} IEncoding
|
||||
* @template TIn, TFormat, TOut
|
||||
*/
|
Reference in New Issue
Block a user