1

I am getting a file "abc.txt" from server and dispaying it in a text area for editing.

<div id="filecontents"> <textarea>  CONTENTS OF FILE LARGER THAN 10KB
 </textarea> </div>

The contents of the file are potentially large. The user will edit the textarea and add/delete text from any part(not just the end). I want to send ONLY the changes to the server for patching. How do I accomplish this?. Is there a javascript version of the popular linux command(diff). John Resig's diff code may not work as, for me, it will involve additional parsing on server side.

Thanks!

4
  • 1
    why not just replace the whole thing? Processing the new sting against the old string would be slower and more resource intensive than just doing a replacement. Commented Oct 3, 2012 at 3:03
  • 2
    Lets say that you do this diff in Javascript... You send up only the changes. Now what? How do you know where these changes are? How are you going to make the changes where they need to be? It would be easier, mind you it would use more bandwidth, and less computational power to just send the entire file back up... Sounds like you should invest some time to learning to use something like git, and introduce it to whomever this thing is targeted at. Commented Oct 3, 2012 at 3:08
  • @Dagon, I understand that the processing can be resource intensive. But the changes are small typo changes. So I think client can handle it. Commented Oct 3, 2012 at 15:43
  • @Justin, change information must also contain where information also! Commented Oct 3, 2012 at 15:45

1 Answer 1

1

You should take a look at google-diff-match-patch, it looks like it should do what you want.

Sign up to request clarification or add additional context in comments.

1 Comment

@ultranut, This looks like what I am looking for. I will use it and let you know the performance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.