title: Using JavaScript to truncate text to a certain size (8 KB)
body: <p>I'm using the <a href="http://www.zemanta.com/" rel="noreferrer">Zemanta</a> API, which accepts up to 8 KB of text per call. I'm extracting the text to send to Zemanta from Web pages using JavaScript, so I'm looking for a function that will truncate my text at exactly 8 KB.</p>
  
  <p>Zemanta should do this truncation on its own (i.e., if you send it a larger string), but I need to shuttle this text around a bit before making the API call, so I want to keep the payload as small as possible.</p>
  
  <p>Is it safe to assume that 8 KB of text is 8,192 characters, and to truncate accordingly? (1 byte per character; 1,024 characters per KB; 8 KB = 8,192 bytes/characters) Or, is that inaccurate or only true given certain circumstances?</p>
  
  <p>Is there a more elegant way to truncate a string based on its actual file size?</p>