MCPcopy Create free account
hub / github.com/codeHappyDananx/SpecWave / encodeTextBuffer

Function encodeTextBuffer

electron/main.js:675–697  ·  view source on GitHub ↗
(text, options)

Source from the content-addressed store, hash-verified

673}
674
675function encodeTextBuffer(text, options) {
676 const encoding = options?.encoding || 'utf8'
677 const bom = options?.bom || 'none'
678 const eol = options?.eol || '\n'
679 const normalizedText = normalizeEol(text, eol)
680
681 if (encoding === 'utf16le') {
682 const body = Buffer.from(normalizedText, 'utf16le')
683 if (bom === 'utf16le') return Buffer.concat([Buffer.from([0xff, 0xfe]), body])
684 return body
685 }
686
687 if (encoding === 'utf16be') {
688 const body = Buffer.from(normalizedText, 'utf16le')
689 if (body.length >= 2) body.swap16()
690 if (bom === 'utf16be') return Buffer.concat([Buffer.from([0xfe, 0xff]), body])
691 return body
692 }
693
694 const body = Buffer.from(normalizedText, 'utf8')
695 if (bom === 'utf8') return Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), body])
696 return body
697}
698
699// 读取目录结构 - 支持所有文件
700function readDirectoryTree(dirPath, basePath = '', maxDepth = null, currentDepth = 0) {

Callers 1

main.jsFile · 0.85

Calls 1

normalizeEolFunction · 0.85

Tested by

no test coverage detected