mirror of
https://github.com/PR0M3TH3AN/text_splitter.git
synced 2025-09-08 07:18:42 +00:00
update
This commit is contained in:
@@ -110,20 +110,22 @@
|
|||||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
||||||
|
|
||||||
// Split the text into chunks
|
// Prepare the prefix for the first chunk
|
||||||
for (let i = 0; i < text.length; i += maxChunkSize) {
|
const firstChunkPrefix = `Hash: ${hashHex}\nMessage 1/`;
|
||||||
|
const firstChunkContentSize = maxChunkSize - firstChunkPrefix.length - (String(text.length).length + 2);
|
||||||
|
const firstChunk = firstChunkPrefix + text.substring(0, firstChunkContentSize);
|
||||||
|
|
||||||
|
// Add the first chunk to the list
|
||||||
|
chunks.push(firstChunk);
|
||||||
|
|
||||||
|
// Split the remaining text into chunks
|
||||||
|
for (let i = firstChunkContentSize; i < text.length; i += maxChunkSize) {
|
||||||
let chunk = text.substring(i, i + maxChunkSize);
|
let chunk = text.substring(i, i + maxChunkSize);
|
||||||
let chunkNumber = Math.floor(i / maxChunkSize) + 1;
|
let chunkNumber = Math.floor(i / maxChunkSize) + 2; // Start from the second chunk
|
||||||
let totalChunks = Math.ceil(text.length / maxChunkSize);
|
let totalChunks = Math.ceil(text.length / maxChunkSize) + 1;
|
||||||
let prefix = `Message ${chunkNumber}/${totalChunks}`;
|
let prefix = `Message ${chunkNumber}/${totalChunks}`;
|
||||||
|
|
||||||
// Add the hash only to the first chunk
|
|
||||||
if (chunkNumber === 1) {
|
|
||||||
chunk = `Hash: ${hashHex}\n${prefix}\n\n${chunk}`;
|
|
||||||
} else {
|
|
||||||
chunk = `${prefix}\n\n${chunk}`;
|
chunk = `${prefix}\n\n${chunk}`;
|
||||||
}
|
|
||||||
|
|
||||||
chunks.push(chunk);
|
chunks.push(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user